Skip to content

Commit 53ceabd

Browse files
Additional SmartHint refactoring (#3181)
* Initial work of respecting TextBox.Height - only done for TextBox so far * Aligning prefix/suffix texts * PasswordBox respects VerticalContentAlignment Icons still need alignment * Fixes hint floating position for default offset * DatePicker now respects VerticalContentAlignment * TimePicker now respects VerticalContentAlignment * Renamed element to match content * PasswordBox trailing icons/buttons now respect VerticalContentAlignment * ComboBox clear button now respects VerticalContentAlignment * ComboBox toggle button now respects VerticalContentAlignment * Improved 'Smart Hint' demo app page * Added FontSize to 'Smart Hint' demo app page * Change default VerticalContentAlignment of ComboBox to Center * Apply red color to FontSize in 'Smart Hint' demo page Currently only the default FontSize is correctly supported. * Use FontFamily from "hint" as input to floating offset converter * Add support for controlling FontFamily in 'Smart Hint' demo page * Add comment in demo app page regarding ShowMeTheXaml * Fix typo * Fix for broken UI tests for DatePicker and TimePicker * Fix broken UI tests for PasswordBox * Apply same visibility fix for TextBox as was done to PasswordBox, etc. The TextBox also uses the "IsHintInFloatingPosition" AP for the prefix text. I did not touch this as it still collapses it when the prefix text is not set. * Align ComboBox prefix/suffix text margin and visibility with other ctrls * Use HelperTextStyle in ComboBox, DatePicker, and TimePicker Also uses the helper text in the 'Smart Hint' demo app for a warning * Set default VerticalContentAlignment=Center for Date- and TimePicker Fixes failing UI test * Fixed failing unit tests for FloatingHintTransformConverter
1 parent 5ef62a0 commit 53ceabd

16 files changed

+957
-239
lines changed

MainDemo.Wpf/Domain/SmartHintViewModel.cs

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1-
using MaterialDesignThemes.Wpf;
1+
using System.Windows.Media;
2+
using MaterialDesignThemes.Wpf;
23

34
namespace MaterialDesignDemo.Domain;
45

56
internal class SmartHintViewModel : ViewModelBase
67
{
8+
public static Point DefaultFloatingOffset { get; } = new(0, -16);
9+
public static FontFamily DefaultFontFamily = (FontFamily)new MaterialDesignFontExtension().ProvideValue(null!);
10+
711
private bool _floatHint = true;
812
private FloatingHintHorizontalAlignment _selectedAlignment = FloatingHintHorizontalAlignment.Inherit;
913
private double _selectedFloatingScale = 0.75;
1014
private bool _showClearButton = true;
1115
private bool _showLeadingIcon = true;
16+
private bool _showTrailingIcon = true;
1217
private string _hintText = "Hint text";
1318
private string _helperText = "Helper text";
14-
private Point _selectedFloatingOffset = new(0, -16);
19+
private Point _selectedFloatingOffset = DefaultFloatingOffset;
1520
private bool _applyCustomPadding;
1621
private Thickness _selectedCustomPadding = new(5);
22+
private double _selectedCustomHeight = double.NaN;
23+
private VerticalAlignment _selectedVerticalAlignment = VerticalAlignment.Center;
24+
private double _selectedLeadingIconSize = 20;
25+
private double _selectedTrailingIconSize = 20;
26+
private string? _prefixText;
27+
private string? _suffixText;
28+
private double _selectedFontSize = double.NaN;
29+
private FontFamily? _selectedFontFamily = DefaultFontFamily;
1730

1831
public IEnumerable<FloatingHintHorizontalAlignment> HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType<FloatingHintHorizontalAlignment>();
1932
public IEnumerable<double> FloatingScaleOptions { get; } = new[] {0.25, 0.5, 0.75, 1.0};
20-
public IEnumerable<Point> FloatingOffsetOptions { get; } = new[] { new Point(0, -16), new Point(0, 16), new Point(16, 16), new Point(-16, -16) };
33+
public IEnumerable<Point> FloatingOffsetOptions { get; } = new[] { DefaultFloatingOffset, new Point(0, -25), new Point(16, -16), new Point(-16, -16), new Point(0, -50) };
2134
public IEnumerable<string> ComboBoxOptions { get; } = new[] {"Option 1", "Option 2", "Option 3"};
2235
public IEnumerable<Thickness> CustomPaddingOptions { get; } = new [] { new Thickness(0), new Thickness(5), new Thickness(10), new Thickness(15) };
36+
public IEnumerable<double> CustomHeightOptions { get; } = new[] { double.NaN, 50, 75, 100 };
37+
public IEnumerable<VerticalAlignment> VerticalAlignmentOptions { get; } = (VerticalAlignment[])Enum.GetValues(typeof(VerticalAlignment));
38+
public IEnumerable<double> IconSizeOptions { get; } = new[] { 10.0, 15, 20, 30, 50, 75 };
39+
public IEnumerable<double> FontSizeOptions { get; } = new[] { double.NaN, 8, 12, 16, 20, 24, 28 };
40+
public IEnumerable<FontFamily> FontFamilyOptions { get; } = new FontFamily[] { DefaultFontFamily }.Concat(Fonts.SystemFontFamilies.OrderBy(f => f.Source));
2341

2442
public bool FloatHint
2543
{
@@ -81,6 +99,16 @@ public bool ShowLeadingIcon
8199
}
82100
}
83101

102+
public bool ShowTrailingIcon
103+
{
104+
get => _showTrailingIcon;
105+
set
106+
{
107+
_showTrailingIcon = value;
108+
OnPropertyChanged();
109+
}
110+
}
111+
84112
public string HintText
85113
{
86114
get => _hintText;
@@ -120,4 +148,84 @@ public Thickness SelectedCustomPadding
120148
OnPropertyChanged();
121149
}
122150
}
151+
152+
public double SelectedCustomHeight
153+
{
154+
get => _selectedCustomHeight;
155+
set
156+
{
157+
_selectedCustomHeight = value;
158+
OnPropertyChanged();
159+
}
160+
}
161+
162+
public VerticalAlignment SelectedVerticalAlignment
163+
{
164+
get => _selectedVerticalAlignment;
165+
set
166+
{
167+
_selectedVerticalAlignment = value;
168+
OnPropertyChanged();
169+
}
170+
}
171+
172+
public double SelectedLeadingIconSize
173+
{
174+
get => _selectedLeadingIconSize;
175+
set
176+
{
177+
_selectedLeadingIconSize = value;
178+
OnPropertyChanged();
179+
}
180+
}
181+
182+
public double SelectedTrailingIconSize
183+
{
184+
get => _selectedTrailingIconSize;
185+
set
186+
{
187+
_selectedTrailingIconSize = value;
188+
OnPropertyChanged();
189+
}
190+
}
191+
192+
public string? PrefixText
193+
{
194+
get => _prefixText;
195+
set
196+
{
197+
_prefixText = value;
198+
OnPropertyChanged();
199+
}
200+
}
201+
202+
public string? SuffixText
203+
{
204+
get => _suffixText;
205+
set
206+
{
207+
_suffixText = value;
208+
OnPropertyChanged();
209+
}
210+
}
211+
212+
public double SelectedFontSize
213+
{
214+
get => _selectedFontSize;
215+
set
216+
{
217+
_selectedFontSize = value;
218+
OnPropertyChanged();
219+
}
220+
}
221+
222+
public FontFamily? SelectedFontFamily
223+
{
224+
get => _selectedFontFamily;
225+
set
226+
{
227+
_selectedFontFamily = value;
228+
OnPropertyChanged();
229+
}
230+
}
123231
}

MainDemo.Wpf/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
88
xmlns:system="clr-namespace:System;assembly=mscorlib"
99
Title="Material Design in XAML"
10-
Width="1100"
10+
Width="1150"
1111
MaxHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}}"
1212
d:DataContext="{d:DesignInstance domain:MainWindowViewModel}"
1313
AutomationProperties.Name="{Binding Title, RelativeSource={RelativeSource Self}}"

0 commit comments

Comments
 (0)