From 74fbbe3b0a450a3d0bd9f936e952987f64e6f42d Mon Sep 17 00:00:00 2001 From: Nicolai Henriksen Date: Mon, 12 Feb 2024 12:11:22 +0100 Subject: [PATCH 1/6] WIP --- MainDemo.Wpf/Domain/SmartHintViewModel.cs | 7 + MainDemo.Wpf/Properties/launchSettings.json | 2 +- MainDemo.Wpf/SmartHint.xaml | 173 +++++++- .../TextFieldPrefixTextVisibilityConverter.cs | 4 +- .../Themes/MaterialDesign2.Defaults.xaml | 1 + .../Themes/MaterialDesign3.Defaults.xaml | 1 + .../Themes/MaterialDesignTheme.Defaults.xaml | 1 + .../MaterialDesignTheme.TextBoxNew.xaml | 417 ++++++++++++++++++ 8 files changed, 602 insertions(+), 4 deletions(-) create mode 100644 MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBoxNew.xaml diff --git a/MainDemo.Wpf/Domain/SmartHintViewModel.cs b/MainDemo.Wpf/Domain/SmartHintViewModel.cs index 13927bf41e..4fefdcb804 100644 --- a/MainDemo.Wpf/Domain/SmartHintViewModel.cs +++ b/MainDemo.Wpf/Domain/SmartHintViewModel.cs @@ -27,6 +27,7 @@ internal class SmartHintViewModel : ViewModelBase private string? _suffixText; private double _selectedFontSize = double.NaN; private FontFamily? _selectedFontFamily = DefaultFontFamily; + private bool? controlsEnabled = true; public IEnumerable HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType(); public IEnumerable FloatingScaleOptions { get; } = new[] {0.25, 0.5, 0.75, 1.0}; @@ -228,4 +229,10 @@ public FontFamily? SelectedFontFamily OnPropertyChanged(); } } + + public bool? ControlsEnabled + { + get => controlsEnabled; + set => SetProperty(ref controlsEnabled, value); + } } diff --git a/MainDemo.Wpf/Properties/launchSettings.json b/MainDemo.Wpf/Properties/launchSettings.json index 3b8cbc0041..04d2d71911 100644 --- a/MainDemo.Wpf/Properties/launchSettings.json +++ b/MainDemo.Wpf/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Demo App": { "commandName": "Project", - "commandLineArgs": "-p Home -t Inherit -f LeftToRight" + "commandLineArgs": "-p \"Smart Hint\" -t Inherit -f LeftToRight" } } } diff --git a/MainDemo.Wpf/SmartHint.xaml b/MainDemo.Wpf/SmartHint.xaml index 8a024a4002..f39ffc5f27 100644 --- a/MainDemo.Wpf/SmartHint.xaml +++ b/MainDemo.Wpf/SmartHint.xaml @@ -164,7 +164,11 @@ Header="Control Settings" Style="{StaticResource MaterialDesignCardGroupBox}"> + + VerticalAlignment="Top" + IsEnabled="{Binding ControlsEnabled}"> + + + + + + + + + + + + + + + + MaterialDesignFloatingHintTextBoxNew + + + + + + + + + + + + + + + + + + + + + + + + + + MaterialDesignFilledTextBoxNew + + + + + + + + + + + + + + + + + + + + + + + + + + MaterialDesignOutlinedTextBoxNew + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2d00882ba12bcafcb4dcbeb9026ff6a7414246ba Mon Sep 17 00:00:00 2001 From: Nicolai Henriksen Date: Fri, 16 Feb 2024 14:03:48 +0100 Subject: [PATCH 2/6] Move VerticalAlignmentConverter to its own file --- .../TextFieldClearButtonVisibilityConverter.cs | 4 +++- .../Converters/VerticalAlignmentConverter.cs | 14 ++++++++++++++ MaterialDesignThemes.Wpf/SmartHint.cs | 12 ------------ .../Themes/MaterialDesignTheme.ComboBox.xaml | 2 +- .../Themes/MaterialDesignTheme.DatePicker.xaml | 2 +- .../Themes/MaterialDesignTheme.PasswordBox.xaml | 2 +- .../Themes/MaterialDesignTheme.SmartHint.xaml | 2 +- .../Themes/MaterialDesignTheme.TextBox.xaml | 2 +- .../Themes/MaterialDesignTheme.TimePicker.xaml | 2 +- 9 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 MaterialDesignThemes.Wpf/Converters/VerticalAlignmentConverter.cs diff --git a/MaterialDesignThemes.Wpf/Converters/TextFieldClearButtonVisibilityConverter.cs b/MaterialDesignThemes.Wpf/Converters/TextFieldClearButtonVisibilityConverter.cs index 8f2c4c3b16..99f2b9f481 100644 --- a/MaterialDesignThemes.Wpf/Converters/TextFieldClearButtonVisibilityConverter.cs +++ b/MaterialDesignThemes.Wpf/Converters/TextFieldClearButtonVisibilityConverter.cs @@ -5,13 +5,15 @@ namespace MaterialDesignThemes.Wpf.Converters; internal class TextFieldClearButtonVisibilityConverter : IMultiValueConverter { + public Visibility ContentEmptyVisibility { get; set; } = Visibility.Hidden; + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (!(bool)values[0]) // TextFieldAssist.HasClearButton return Visibility.Collapsed; return (bool)values[1] // Hint.IsContentNullOrEmpty - ? Visibility.Hidden + ? ContentEmptyVisibility : Visibility.Visible; } diff --git a/MaterialDesignThemes.Wpf/Converters/VerticalAlignmentConverter.cs b/MaterialDesignThemes.Wpf/Converters/VerticalAlignmentConverter.cs new file mode 100644 index 0000000000..37e6291320 --- /dev/null +++ b/MaterialDesignThemes.Wpf/Converters/VerticalAlignmentConverter.cs @@ -0,0 +1,14 @@ +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 8a23d2908c..988cd69169 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" /> - + + + diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBoxNew.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBoxNew.xaml index 3a17e49ef7..5df57ba635 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBoxNew.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.TextBoxNew.xaml @@ -181,7 +181,7 @@ UseLayoutRounding="{TemplateBinding UseLayoutRounding}" VerticalScrollBarVisibility="Hidden" /> - - + - - + + Date: Sat, 17 Feb 2024 20:45:55 +0100 Subject: [PATCH 5/6] Additions to SmartHint demo app page --- MainDemo.Wpf/Domain/SmartHintViewModel.cs | 13 ++++++++ MainDemo.Wpf/SmartHint.xaml | 38 ++++++++++++++++++++--- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/MainDemo.Wpf/Domain/SmartHintViewModel.cs b/MainDemo.Wpf/Domain/SmartHintViewModel.cs index 4fefdcb804..6dd9a8cdac 100644 --- a/MainDemo.Wpf/Domain/SmartHintViewModel.cs +++ b/MainDemo.Wpf/Domain/SmartHintViewModel.cs @@ -28,6 +28,7 @@ internal class SmartHintViewModel : ViewModelBase private double _selectedFontSize = double.NaN; private FontFamily? _selectedFontFamily = DefaultFontFamily; private bool? controlsEnabled = true; + private int _maxLength = 50; public IEnumerable HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType(); public IEnumerable FloatingScaleOptions { get; } = new[] {0.25, 0.5, 0.75, 1.0}; @@ -235,4 +236,16 @@ public bool? ControlsEnabled get => controlsEnabled; set => SetProperty(ref controlsEnabled, value); } + + public bool? ShowCharacterCounter + { + get => MaxLength > 0; + set => MaxLength = value == true ? 50 : 0; + } + + public int MaxLength + { + get => _maxLength; + set => SetProperty(ref _maxLength, value); + } } diff --git a/MainDemo.Wpf/SmartHint.xaml b/MainDemo.Wpf/SmartHint.xaml index f39ffc5f27..fbfb0f9e5c 100644 --- a/MainDemo.Wpf/SmartHint.xaml +++ b/MainDemo.Wpf/SmartHint.xaml @@ -155,6 +155,10 @@ IsEnabled="{Binding ElementName=CheckBoxTrailingIcon, Path=IsChecked}" ItemsSource="{Binding IconSizeOptions}" SelectedItem="{Binding SelectedTrailingIconSize, Mode=TwoWay}" /> + @@ -255,8 +259,11 @@ + + + @@ -289,7 +296,12 @@ IsEnabled="{Binding ControlsEnabled}"> - + + + + @@ -332,6 +346,7 @@ + @@ -350,7 +366,7 @@ - + @@ -370,6 +386,8 @@ + + @@ -384,6 +402,7 @@ + @@ -402,7 +422,7 @@ - + @@ -422,6 +442,8 @@ + + @@ -436,6 +458,7 @@ + @@ -479,6 +503,8 @@ + + @@ -531,6 +557,8 @@ + + @@ -583,6 +611,8 @@ + + From 33487d11fd0ccf835fd29ce72107ff6ff242a277 Mon Sep 17 00:00:00 2001 From: Nicolai Henriksen Date: Sat, 17 Feb 2024 21:45:00 +0100 Subject: [PATCH 6/6] Remove debug color from new SmartHint --- .../Themes/MaterialDesignTheme.SmartHintNew.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.SmartHintNew.xaml b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.SmartHintNew.xaml index e93bd6af4d..48508a9ff5 100644 --- a/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.SmartHintNew.xaml +++ b/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.SmartHintNew.xaml @@ -143,7 +143,7 @@ + ClipToBounds="True">