Skip to content

Commit dd9c6f9

Browse files
Fix clipping of SmartHint when FloatingScale > 1 (#3544)
* Update demo app with better options to test the issue * Fix the hint container margin issue * Fix hint clipping issue
1 parent d410c05 commit dd9c6f9

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

src/MainDemo.Wpf/Domain/SmartHintViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ internal class SmartHintViewModel : ViewModelBase
4545
private Thickness _outlineStyleActiveBorderThickness = new(2);
4646

4747
public IEnumerable<FloatingHintHorizontalAlignment> HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType<FloatingHintHorizontalAlignment>();
48-
public IEnumerable<double> FloatingScaleOptions { get; } = [0.25, 0.5, 0.75, 1.0];
49-
public IEnumerable<Point> FloatingOffsetOptions { get; } = [DefaultFloatingOffset, new Point(0, -25), new Point(0, -16), new Point(16, -16), new Point(-16, -16), new Point(0, -50)];
48+
public IEnumerable<double> FloatingScaleOptions { get; } = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0];
49+
public IEnumerable<Point> FloatingOffsetOptions { get; } = [DefaultFloatingOffset, new Point(0, -25), new Point(0, -16), new Point(16, -16), new Point(-16, -16), new Point(0, -50), new Point(-50, -50), new Point(50, -50)];
5050
public IEnumerable<string> ComboBoxOptions { get; } = ["Option 1", "Option 2", "Option 3"];
5151
public IEnumerable<Thickness> CustomPaddingOptions { get; } = [new Thickness(0), new Thickness(5), new Thickness(10), new Thickness(15)];
5252
public IEnumerable<double> CustomHeightOptions { get; } = [double.NaN, 50, 75, 100, 150];
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Globalization;
2+
using System.Windows.Data;
3+
using System.Windows.Media;
4+
5+
namespace MaterialDesignThemes.Wpf.Converters;
6+
7+
public class FloatingHintClippingGridConverter : IValueConverter
8+
{
9+
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
10+
value switch
11+
{
12+
double actualWidth => new RectangleGeometry(new Rect(new Point(0, 0), new Size(actualWidth, double.MaxValue))),
13+
_ => null
14+
};
15+
16+
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
17+
=> throw new NotImplementedException();
18+
}

src/MaterialDesignThemes.Wpf/Converters/FloatingHintContainerMarginConverter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ public class FloatingHintContainerMarginConverter : IMultiValueConverter
99

1010
public object? Convert(object?[]? values, Type targetType, object? parameter, CultureInfo culture)
1111
{
12-
if (values is [double scale, Thickness floatingMargin])
12+
if (values is [double scale, Thickness floatingMargin, double floatingScale])
1313
{
1414
return floatingMargin with
1515
{
16-
Left = floatingMargin.Left * scale,
17-
Top = floatingMargin.Top * scale,
18-
Right = floatingMargin.Right * scale,
19-
Bottom = floatingMargin.Bottom * scale,
16+
Left = (floatingMargin.Left * scale) / floatingScale,
17+
Top = (floatingMargin.Top * scale) / floatingScale,
18+
Right = (floatingMargin.Right * scale) / floatingScale,
19+
Bottom = (floatingMargin.Bottom * scale) / floatingScale
2020
};
2121
}
2222
return EmptyThickness;

src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.SmartHint.xaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
44
xmlns:system="clr-namespace:System;assembly=mscorlib"
@@ -16,6 +16,7 @@
1616
<converters:FloatingHintScaleTransformConverter x:Key="FloatingHintScaleTransformConverter" />
1717
<converters:FloatingHintContainerMarginConverter x:Key="FloatingHintContainerMarginConverter" />
1818
<converters:FloatingHintTextBlockMarginConverter x:Key="FloatingHintTextBlockMarginConverter" />
19+
<converters:FloatingHintClippingGridConverter x:Key="FloatingHintClippingGridConverter" />
1920
</Style.Resources>
2021
<Setter Property="HorizontalAlignment" Value="Stretch" />
2122
<Setter Property="HorizontalContentAlignment" Value="Left" />
@@ -142,8 +143,7 @@
142143
</VisualStateGroup>
143144
</VisualStateManager.VisualStateGroups>
144145
<wpf:ScaleHost x:Name="ScaleHost" />
145-
<Grid x:Name="HintClippingGrid"
146-
ClipToBounds="True">
146+
<Grid Clip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth, Converter={StaticResource FloatingHintClippingGridConverter}}">
147147
<Grid.RenderTransform>
148148
<MultiBinding Converter="{StaticResource FloatingHintTranslateTransformConverter}">
149149
<Binding ElementName="ScaleHost" Path="Scale" />
@@ -200,6 +200,7 @@
200200
<MultiBinding Converter="{StaticResource FloatingHintContainerMarginConverter}">
201201
<Binding ElementName="ScaleHost" Path="Scale" />
202202
<Binding Path="FloatingMargin" RelativeSource="{RelativeSource TemplatedParent}" />
203+
<Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}" />
203204
</MultiBinding>
204205
</ContentControl.Margin>
205206
</ContentControl>

0 commit comments

Comments
 (0)