Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5923051
Initial work of respecting TextBox.Height - only done for TextBox so far
nicolaihenriksen Apr 25, 2023
ee18094
Aligning prefix/suffix texts
nicolaihenriksen Apr 27, 2023
860bcff
PasswordBox respects VerticalContentAlignment
nicolaihenriksen Apr 27, 2023
18d06d9
Fixes hint floating position for default offset
nicolaihenriksen May 1, 2023
539f009
DatePicker now respects VerticalContentAlignment
nicolaihenriksen May 1, 2023
0818e7b
TimePicker now respects VerticalContentAlignment
nicolaihenriksen May 1, 2023
c74f17f
Renamed element to match content
nicolaihenriksen May 1, 2023
31145a0
PasswordBox trailing icons/buttons now respect VerticalContentAlignment
nicolaihenriksen May 1, 2023
8c482ce
ComboBox clear button now respects VerticalContentAlignment
nicolaihenriksen May 1, 2023
00e4d34
ComboBox toggle button now respects VerticalContentAlignment
nicolaihenriksen May 1, 2023
bf2dedc
Improved 'Smart Hint' demo app page
nicolaihenriksen May 1, 2023
91f653c
Added FontSize to 'Smart Hint' demo app page
nicolaihenriksen May 1, 2023
2edf542
Change default VerticalContentAlignment of ComboBox to Center
nicolaihenriksen May 2, 2023
13dcc23
Apply red color to FontSize in 'Smart Hint' demo page
nicolaihenriksen May 2, 2023
9570007
Use FontFamily from "hint" as input to floating offset converter
nicolaihenriksen May 2, 2023
0580e60
Add support for controlling FontFamily in 'Smart Hint' demo page
nicolaihenriksen May 2, 2023
7b2a333
Add comment in demo app page regarding ShowMeTheXaml
nicolaihenriksen May 2, 2023
2d9e411
Fix typo
nicolaihenriksen May 2, 2023
5500491
Fix for broken UI tests for DatePicker and TimePicker
nicolaihenriksen May 2, 2023
884d312
Fix broken UI tests for PasswordBox
nicolaihenriksen May 2, 2023
91bd6a7
Apply same visibility fix for TextBox as was done to PasswordBox, etc.
nicolaihenriksen May 2, 2023
76d6f94
Align ComboBox prefix/suffix text margin and visibility with other ctrls
nicolaihenriksen May 2, 2023
b717ad5
Use HelperTextStyle in ComboBox, DatePicker, and TimePicker
nicolaihenriksen May 2, 2023
bef99f5
Set default VerticalContentAlignment=Center for Date- and TimePicker
nicolaihenriksen May 2, 2023
95d9075
Fixed failing unit tests for FloatingHintTransformConverter
nicolaihenriksen May 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Initial work of respecting TextBox.Height - only done for TextBox so far
  • Loading branch information
nicolaihenriksen committed May 1, 2023
commit 59230512df0292343b6ee5828d11fe36541fbf94
82 changes: 81 additions & 1 deletion MainDemo.Wpf/Domain/SmartHintViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ internal class SmartHintViewModel : ViewModelBase
private double _selectedFloatingScale = 0.75;
private bool _showClearButton = true;
private bool _showLeadingIcon = true;
private bool _showTrailingIcon = true;
private string _hintText = "Hint text";
private string _helperText = "Helper text";
private Point _selectedFloatingOffset = new(0, -16);
private bool _applyCustomPadding;
private Thickness _selectedCustomPadding = new(5);
private double _selectedCustomHeight = double.NaN;
private VerticalAlignment _selectedVerticalAlignment = VerticalAlignment.Center;
private double _selectedLeadingIconSize = 20;
private double _selectedTrailingIconSize = 20;
private string? _prefixText;
private string? _suffixText;

public IEnumerable<FloatingHintHorizontalAlignment> HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType<FloatingHintHorizontalAlignment>();
public IEnumerable<double> FloatingScaleOptions { get; } = new[] {0.25, 0.5, 0.75, 1.0};
public IEnumerable<Point> FloatingOffsetOptions { get; } = new[] { new Point(0, -16), new Point(0, 16), new Point(16, 16), new Point(-16, -16) };
public IEnumerable<Point> FloatingOffsetOptions { get; } = new[] { new Point(0, -16), new Point(0, 16), new Point(16, 16), new Point(-16, -16), new Point(0, -40) };
public IEnumerable<string> ComboBoxOptions { get; } = new[] {"Option 1", "Option 2", "Option 3"};
public IEnumerable<Thickness> CustomPaddingOptions { get; } = new [] { new Thickness(0), new Thickness(5), new Thickness(10), new Thickness(15) };
public IEnumerable<double> CustomHeightOptions { get; } = new[] { double.NaN, 50, 75, 100 };
public IEnumerable<VerticalAlignment> VerticalAlignmentOptions { get; } = (VerticalAlignment[])Enum.GetValues(typeof(VerticalAlignment));
public IEnumerable<double> IconSizeOptions { get; } = new[] { 10.0, 15, 20, 30, 50, 75 };

public bool FloatHint
{
Expand Down Expand Up @@ -81,6 +91,16 @@ public bool ShowLeadingIcon
}
}

public bool ShowTrailingIcon
{
get => _showTrailingIcon;
set
{
_showTrailingIcon = value;
OnPropertyChanged();
}
}

public string HintText
{
get => _hintText;
Expand Down Expand Up @@ -120,4 +140,64 @@ public Thickness SelectedCustomPadding
OnPropertyChanged();
}
}

public double SelectedCustomHeight
{
get => _selectedCustomHeight;
set
{
_selectedCustomHeight = value;
OnPropertyChanged();
}
}

public VerticalAlignment SelectedVerticalAlignment
{
get => _selectedVerticalAlignment;
set
{
_selectedVerticalAlignment = value;
OnPropertyChanged();
}
}

public double SelectedLeadingIconSize
{
get => _selectedLeadingIconSize;
set
{
_selectedLeadingIconSize = value;
OnPropertyChanged();
}
}

public double SelectedTrailingIconSize
{
get => _selectedTrailingIconSize;
set
{
_selectedTrailingIconSize = value;
OnPropertyChanged();
}
}

public string? PrefixText
{
get => _prefixText;
set
{
_prefixText = value;
OnPropertyChanged();
}
}

public string? SuffixText
{
get => _suffixText;
set
{
_suffixText = value;
OnPropertyChanged();
}
}
}
2 changes: 1 addition & 1 deletion MainDemo.Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=mscorlib"
Title="Material Design in XAML"
Width="1100"
Width="1150"
MaxHeight="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}}"
d:DataContext="{d:DesignInstance domain:MainWindowViewModel}"
AutomationProperties.Name="{Binding Title, RelativeSource={RelativeSource Self}}"
Expand Down
374 changes: 263 additions & 111 deletions MainDemo.Wpf/SmartHint.xaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ internal class FloatingHintTransformConverter : IMultiValueConverter

public object? Convert(object?[]? values, Type targetType, object? parameter, CultureInfo culture)
{
if (values?.Length != 4
if (values?.Length != 5
|| values.Any(v => v == null)
|| !double.TryParse(values[0]!.ToString(), out double scale)
|| !double.TryParse(values[1]!.ToString(), out double lower)
|| !double.TryParse(values[2]!.ToString(), out double upper)
|| values[3] is not Point floatingOffset)
|| values[3] is not Point floatingOffset
|| !double.TryParse(values[4]!.ToString(), out double initialVerticalOffset))
{
return Transform.Identity;
}
Expand All @@ -34,10 +35,13 @@ internal class FloatingHintTransformConverter : IMultiValueConverter
}
if (ApplyTranslateTransform)
{
/* As a consequence of Math.Min() which is used below to ensure the initial offset is respected (in filled style)
the SmartHint will not be able to "float downwards". I believe this is acceptable though.
*/
transformGroup.Children.Add(new TranslateTransform
{
X = scale * floatingOffset.X,
Y = scale * floatingOffset.Y
Y = Math.Min(initialVerticalOffset, scale * floatingOffset.Y)
});
}
return transformGroup;
Expand Down
13 changes: 9 additions & 4 deletions MaterialDesignThemes.Wpf/Converters/ThicknessCloneConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ public class ThicknessCloneConverter : IValueConverter
public double? FixedRight { get; set; }
public double? FixedBottom { get; set; }

public double AdditionalOffsetLeft { get; set; }
public double AdditionalOffsetTop { get; set; }
public double AdditionalOffsetRight { get; set; }
public double AdditionalOffsetBottom { get; set; }

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Thickness thickness)
{
double left = FixedLeft ?? (CloneEdges.HasFlag(ThicknessEdges.Left) ? thickness.Left : NonClonedEdgeValue);
double top = FixedTop ?? (CloneEdges.HasFlag(ThicknessEdges.Top) ? thickness.Top : NonClonedEdgeValue);
double right = FixedRight ?? (CloneEdges.HasFlag(ThicknessEdges.Right) ? thickness.Right : NonClonedEdgeValue);
double bottom = FixedBottom ?? (CloneEdges.HasFlag(ThicknessEdges.Bottom) ? thickness.Bottom : NonClonedEdgeValue);
double left = (FixedLeft ?? (CloneEdges.HasFlag(ThicknessEdges.Left) ? thickness.Left : NonClonedEdgeValue)) + AdditionalOffsetLeft;
double top = (FixedTop ?? (CloneEdges.HasFlag(ThicknessEdges.Top) ? thickness.Top : NonClonedEdgeValue)) + AdditionalOffsetTop;
double right = (FixedRight ?? (CloneEdges.HasFlag(ThicknessEdges.Right) ? thickness.Right : NonClonedEdgeValue)) + AdditionalOffsetRight;
double bottom = (FixedBottom ?? (CloneEdges.HasFlag(ThicknessEdges.Bottom) ? thickness.Bottom : NonClonedEdgeValue)) + AdditionalOffsetBottom;
return new Thickness(left, top, right, bottom);
}
return DependencyProperty.UnsetValue;
Expand Down
9 changes: 9 additions & 0 deletions MaterialDesignThemes.Wpf/SmartHint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public double HintOpacity

#endregion

public static readonly DependencyProperty InitialVerticalOffsetProperty = DependencyProperty.Register(
nameof(InitialVerticalOffset), typeof(double), typeof(SmartHint), new PropertyMetadata(default(double)));

public double InitialVerticalOffset
{
get { return (double) GetValue(InitialVerticalOffsetProperty); }
set { SetValue(InitialVerticalOffsetProperty, value); }
}

static SmartHint()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SmartHint), new FrameworkPropertyMetadata(typeof(SmartHint)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Source="{StaticResource NoContentFloatingScale}" />
<Binding Path="FloatingOffset" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="InitialVerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</Grid.RenderTransform>
<Canvas HorizontalAlignment="Left" Width="{Binding ElementName=FloatingHintTextBlock, Path= ActualWidth}" Height="{Binding ElementName=FloatingHintTextBlock, Path=ActualHeight}">
Expand Down Expand Up @@ -182,6 +183,7 @@
<Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Source="{StaticResource NoContentFloatingScale}" />
<Binding Path="FloatingOffset" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="InitialVerticalOffset" RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</ContentControl.RenderTransform>
</ContentControl>
Expand Down
Loading