diff --git a/MainDemo.Wpf/Domain/SmartHintViewModel.cs b/MainDemo.Wpf/Domain/SmartHintViewModel.cs index 13927bf41e..de86d850a8 100644 --- a/MainDemo.Wpf/Domain/SmartHintViewModel.cs +++ b/MainDemo.Wpf/Domain/SmartHintViewModel.cs @@ -27,6 +27,10 @@ internal class SmartHintViewModel : ViewModelBase private string? _suffixText; private double _selectedFontSize = double.NaN; private FontFamily? _selectedFontFamily = DefaultFontFamily; + private bool _controlsEnabled = true; + private bool _rippleOnFocus = false; + private bool _textBoxAcceptsReturn = false; + private int _maxLength; public IEnumerable HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType(); public IEnumerable FloatingScaleOptions { get; } = new[] {0.25, 0.5, 0.75, 1.0}; @@ -42,190 +46,148 @@ internal class SmartHintViewModel : ViewModelBase public bool FloatHint { get => _floatHint; - set - { - _floatHint = value; - OnPropertyChanged(); - } + set => SetProperty(ref _floatHint, value); } public FloatingHintHorizontalAlignment SelectedAlignment { get => _selectedAlignment; - set - { - _selectedAlignment = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedAlignment, value); } public double SelectedFloatingScale { get => _selectedFloatingScale; - set - { - _selectedFloatingScale = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedFloatingScale, value); } public Point SelectedFloatingOffset { get => _selectedFloatingOffset; - set - { - _selectedFloatingOffset = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedFloatingOffset, value); } public bool ShowClearButton { get => _showClearButton; - set - { - _showClearButton = value; - OnPropertyChanged(); - } + set => SetProperty(ref _showClearButton, value); } public bool ShowLeadingIcon { get => _showLeadingIcon; - set - { - _showLeadingIcon = value; - OnPropertyChanged(); - } + set => SetProperty(ref _showLeadingIcon, value); } public bool ShowTrailingIcon { get => _showTrailingIcon; - set - { - _showTrailingIcon = value; - OnPropertyChanged(); - } + set => SetProperty(ref _showTrailingIcon, value); } public string HintText { get => _hintText; - set - { - _hintText = value; - OnPropertyChanged(); - } + set => SetProperty(ref _hintText, value); } public string HelperText { get => _helperText; - set - { - _helperText = value; - OnPropertyChanged(); - } + set => SetProperty(ref _helperText, value); } public bool ApplyCustomPadding { get => _applyCustomPadding; - set - { - _applyCustomPadding = value; - OnPropertyChanged(); - } + set => SetProperty(ref _applyCustomPadding, value); } public Thickness SelectedCustomPadding { get => _selectedCustomPadding; - set - { - _selectedCustomPadding = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedCustomPadding, value); } public double SelectedCustomHeight { get => _selectedCustomHeight; - set - { - _selectedCustomHeight = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedCustomHeight, value); } public VerticalAlignment SelectedVerticalAlignment { get => _selectedVerticalAlignment; - set - { - _selectedVerticalAlignment = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedVerticalAlignment, value); } public double SelectedLeadingIconSize { get => _selectedLeadingIconSize; - set - { - _selectedLeadingIconSize = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedLeadingIconSize, value); } public double SelectedTrailingIconSize { get => _selectedTrailingIconSize; - set - { - _selectedTrailingIconSize = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedTrailingIconSize, value); } public string? PrefixText { get => _prefixText; - set - { - _prefixText = value; - OnPropertyChanged(); - } + set => SetProperty(ref _prefixText, value); } public string? SuffixText { get => _suffixText; - set - { - _suffixText = value; - OnPropertyChanged(); - } + set => SetProperty(ref _suffixText, value); } public double SelectedFontSize { get => _selectedFontSize; - set - { - _selectedFontSize = value; - OnPropertyChanged(); - } + set => SetProperty(ref _selectedFontSize, value); } public FontFamily? SelectedFontFamily { get => _selectedFontFamily; + set => SetProperty(ref _selectedFontFamily, value); + } + + public bool ControlsEnabled + { + get => _controlsEnabled; + set => SetProperty(ref _controlsEnabled, value); + } + + public bool RippleOnFocus + { + get => _rippleOnFocus; + set => SetProperty(ref _rippleOnFocus, value); + } + + public bool TextBoxAcceptsReturn + { + get => _textBoxAcceptsReturn; + set => SetProperty(ref _textBoxAcceptsReturn, value); + } + + public bool ShowCharacterCounter + { + get => MaxLength > 0; + set => MaxLength = value == true ? 50 : 0; + } + + public int MaxLength + { + get => _maxLength; set { - _selectedFontFamily = value; - OnPropertyChanged(); + SetProperty(ref _maxLength, value); + OnPropertyChanged(nameof(ShowCharacterCounter)); } } } diff --git a/MainDemo.Wpf/InputElementContentControl.cs b/MainDemo.Wpf/InputElementContentControl.cs new file mode 100644 index 0000000000..6e54f9a1dc --- /dev/null +++ b/MainDemo.Wpf/InputElementContentControl.cs @@ -0,0 +1,9 @@ +namespace MaterialDesignDemo; + +/// +/// ContentControl variation simply used to capture the input elements in the "Smart Hint" demo page and apply some common properties. +/// +internal class InputElementContentControl : ContentControl +{ + public InputElementContentControl() => IsTabStop = false; +} diff --git a/MainDemo.Wpf/Properties/launchSettings.json b/MainDemo.Wpf/Properties/launchSettings.json index aa143eaeea..3b8cbc0041 100644 --- a/MainDemo.Wpf/Properties/launchSettings.json +++ b/MainDemo.Wpf/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Demo App": { "commandName": "Project", - "commandLineArgs": "-p 3DTest -t Inherit -f LeftToRight" + "commandLineArgs": "-p Home -t Inherit -f LeftToRight" } } } diff --git a/MainDemo.Wpf/SmartHint.xaml b/MainDemo.Wpf/SmartHint.xaml index 8a024a4002..ad51ffae28 100644 --- a/MainDemo.Wpf/SmartHint.xaml +++ b/MainDemo.Wpf/SmartHint.xaml @@ -6,7 +6,6 @@ xmlns:local="clr-namespace:MaterialDesignDemo" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:smtx="clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML" xmlns:system="clr-namespace:System;assembly=System.Runtime" x:Name="_root" Margin="-16,0,-16,0" @@ -19,11 +18,7 @@ - - @@ -60,6 +54,7 @@ + @@ -155,6 +150,10 @@ IsEnabled="{Binding ElementName=CheckBoxTrailingIcon, Path=IsChecked}" ItemsSource="{Binding IconSizeOptions}" SelectedItem="{Binding SelectedTrailingIconSize, Mode=TwoWay}" /> + @@ -164,7 +163,15 @@ Header="Control Settings" Style="{StaticResource MaterialDesignCardGroupBox}"> + + @@ -281,14 +289,21 @@ + VerticalAlignment="Top" + IsEnabled="{Binding ControlsEnabled}"> - + + + + @@ -323,23 +340,24 @@ MaterialDesignFloatingHintTextBox - + - - + + - - + + - - + + - + @@ -374,23 +394,24 @@ MaterialDesignFilledTextBox - + - - + + - - + + - - + + - + @@ -425,18 +448,18 @@ MaterialDesignOutlinedTextBox - + - - + + - - + + - - + + - + @@ -446,7 +469,7 @@ @@ -486,18 +509,18 @@ MaterialDesignRichTextBox - + - - + + - - + + - - + + - + @@ -507,7 +530,7 @@ @@ -542,23 +568,23 @@ MaterialDesignFloatingHintPasswordBox - + - - + + - - + + - - + + - + @@ -593,23 +622,23 @@ MaterialDesignFilledPasswordBox - + - - + + - - + + - - + + - + @@ -644,18 +676,18 @@ MaterialDesignOutlinedPasswordBox - + - - + + - - + + - - + + - + @@ -669,7 +701,7 @@ @@ -705,23 +740,23 @@ MaterialDesignFloatingHintRevealPasswordBox - + - - + + - - + + - - + + - + @@ -757,23 +795,23 @@ MaterialDesignFilledRevealPasswordBox - + - - + + - - + + - - + + - + @@ -809,18 +850,18 @@ MaterialDesignOutlinedRevealPasswordBox - + - - + + - - + + - - + + - + @@ -833,7 +874,7 @@ @@ -870,23 +912,23 @@ MaterialDesignFloatingHintComboBox - + - - + + - - + + - - + + - + @@ -923,23 +966,23 @@ MaterialDesignFilledComboBox - + - - + + - - + + - - + + - + @@ -976,18 +1020,18 @@ MaterialDesignOutlinedComboBox - + - - + + - - + + - - + + - + @@ -997,7 +1041,7 @@ @@ -1031,23 +1076,23 @@ MaterialDesignFloatingHintDatePicker - + - - + + - - + + - - + + - + @@ -1081,23 +1127,23 @@ MaterialDesignFilledDatePicker - + - - + + - - + + - - + + - + @@ -1131,18 +1178,18 @@ MaterialDesignOutlinedDatePicker - + - - + + - - + + - - + + - + @@ -1152,7 +1199,7 @@ @@ -1186,23 +1234,23 @@ MaterialDesignFloatingHintTimePicker - + - - + + - - + + - - + + - + @@ -1236,23 +1285,23 @@ MaterialDesignFilledTimePicker - + - - + + - - + + - - + + - + @@ -1286,18 +1336,18 @@ MaterialDesignOutlinedTimePicker - + - - + + - - + + - - + + - + diff --git a/MainDemo.Wpf/SmartHint.xaml.cs b/MainDemo.Wpf/SmartHint.xaml.cs index 10281dda29..fcce3bc45e 100644 --- a/MainDemo.Wpf/SmartHint.xaml.cs +++ b/MainDemo.Wpf/SmartHint.xaml.cs @@ -98,6 +98,18 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, => throw new NotImplementedException(); } +internal class FontSizeConverter : IValueConverter +{ + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + { + double fontSize = (double) value!; + return double.IsNaN(fontSize) ? DependencyProperty.UnsetValue : fontSize; + } + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + => throw new NotImplementedException(); +} + internal abstract class OptionToStringConverter : IValueConverter where TOptionType : notnull { public TOptionType? DefaultValue { get; set; } diff --git a/MaterialDesignThemes.Wpf/Converters/VerticalAlignmentConverter.cs b/MaterialDesignThemes.Wpf/Converters/VerticalAlignmentConverter.cs new file mode 100644 index 0000000000..ce358258fc --- /dev/null +++ b/MaterialDesignThemes.Wpf/Converters/VerticalAlignmentConverter.cs @@ -0,0 +1,15 @@ +using System.Globalization; +using System.Windows.Data; + +namespace MaterialDesignThemes.Wpf.Converters +{ + public class VerticalAlignmentConverter : IValueConverter + { + public VerticalAlignment StretchReplacement { get; set; } = VerticalAlignment.Top; + public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) + => value is VerticalAlignment.Stretch ? StretchReplacement : value; + + public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) + => throw new NotImplementedException(); + } +} diff --git a/MaterialDesignThemes.Wpf/SmartHint.cs b/MaterialDesignThemes.Wpf/SmartHint.cs index 7645cf048d..de82f3c916 100644 --- a/MaterialDesignThemes.Wpf/SmartHint.cs +++ b/MaterialDesignThemes.Wpf/SmartHint.cs @@ -1,6 +1,4 @@ using System.ComponentModel; -using System.Globalization; -using System.Windows.Data; using MaterialDesignThemes.Wpf.Converters; namespace MaterialDesignThemes.Wpf; @@ -237,13 +235,3 @@ private void RefreshState(bool useTransitions) } } } - -public class VerticalAlignmentConverter : IValueConverter -{ - public VerticalAlignment StretchReplacement { get; set; } = VerticalAlignment.Top; - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - => value is VerticalAlignment.Stretch ? StretchReplacement : value; - - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - => throw new NotImplementedException(); -} diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml index 42de0081e1..e4ae3d66d6 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ComboBox.xaml @@ -35,7 +35,7 @@ - + 4 diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DatePicker.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DatePicker.xaml index 4de202b3e5..2aa41799f2 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DatePicker.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DatePicker.xaml @@ -28,7 +28,7 @@ AdditionalOffsetTop="12" CloneEdges="Top,Right,Bottom" FixedLeft="0" /> - +