Skip to content

Commit 96bae97

Browse files
authored
Fix Large values using MaterialDesignDiscreteSlider will cause bad visual #264  (#1707)
* Add TextBox that change Maximum Value of Slider * Add Viewbox for TextBlock
1 parent 4dbd760 commit 96bae97

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

MainDemo.Wpf/Sliders.xaml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,25 @@
4848
<Slider TickFrequency="5" Orientation="Horizontal" TickPlacement="BottomRight" Minimum="1" Maximum="50" Value="25" IsEnabled="False" />
4949
</smtx:XamlDisplay>
5050

51-
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="0" Margin="0 16 0 0">
52-
<TextBlock VerticalAlignment="Bottom">Try me</TextBlock>
53-
<smtx:XamlDisplay Key="slider_6" Margin="8 0 0 0">
54-
<Slider Minimum="0" Maximum="100" Style="{StaticResource MaterialDesignDiscreteSlider}"
55-
ToolTip="MaterialDesignDiscreteSlider"
56-
Value="50"
57-
Width="280" />
58-
</smtx:XamlDisplay>
59-
</StackPanel>
51+
<smtx:XamlDisplay Key="slider_6" Grid.Row="3" Grid.Column="0" Margin="8 0 0 0">
52+
<StackPanel Orientation="Horizontal" Margin="0 16 0 0">
53+
<TextBlock VerticalAlignment="Bottom" Text="Maximum"/>
54+
<TextBox x:Name="sliderMaxH" Text="100000" VerticalAlignment="Bottom"/>
55+
<Slider Minimum="0" Maximum="{Binding Text, ElementName=sliderMaxH, Mode=OneWay}" Style="{StaticResource MaterialDesignDiscreteSlider}"
56+
ToolTip="MaterialDesignDiscreteSlider"
57+
Value="50"
58+
Width="280" />
59+
</StackPanel>
60+
</smtx:XamlDisplay>
6061
<smtx:XamlDisplay Key="slider_7" Grid.Row="4" Grid.Column="0" HorizontalAlignment="Left" Margin="24 8 0 0">
61-
<Slider Orientation="Vertical" Minimum="0" Maximum="100" Height="100"
62+
<StackPanel Orientation="Horizontal" Margin="0 16 0 0">
63+
<TextBlock VerticalAlignment="Center" Text="Maximum"/>
64+
<TextBox x:Name="sliderMaxV" Text="100000" VerticalAlignment="Center"/>
65+
<Slider Orientation="Vertical" Minimum="0" Maximum="{Binding Text, ElementName=sliderMaxV, Mode=OneWay}" Height="100"
6266
Style="{StaticResource MaterialDesignDiscreteSlider}"
6367
ToolTip="MaterialDesignDiscreteSlider"/>
64-
</smtx:XamlDisplay>
65-
</Grid>
68+
</StackPanel>
69+
</smtx:XamlDisplay>
70+
</Grid>
6671
</UserControl>
6772

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Slider.xaml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,21 @@
177177
</Grid.RowDefinitions>
178178
<Viewbox x:Name="Pin" RenderTransformOrigin=".5,1">
179179
<Grid>
180-
<Path Data="M13.437011,33.065002 C9.7268463,29.334181 7.812011,26.379009 4.874511,23.379009 1.687011,19.566509 0.12600673,17.206803 5.6843419E-14,14.127608 0.062010996,2.0027046 11.158781,-0.062991121 13.43702,0.0014351187 M13.438011,33.065016 C17.148173,29.334199 19.063008,26.379023 22.00051,23.379017 25.188007,19.566519 26.749013,17.206806 26.875018,14.127613 26.813007,2.002704 15.716239,-0.062987381 13.438,0.0014388781"
181-
Fill="{TemplateBinding Foreground}"
182-
Grid.Row="0" Margin="-7,2,-8,4" />
183-
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Slider}, Path=Value}" Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"
184-
HorizontalAlignment="Center" VerticalAlignment="Center"
185-
FontWeight="Normal" FontSize="11"
186-
Margin="-7 -6 -7 0"/>
187-
</Grid>
188-
<Viewbox.RenderTransform>
180+
<Path Data="M13.437011,33.065002 C9.7268463,29.334181 7.812011,26.379009 4.874511,23.379009 1.687011,19.566509 0.12600673,17.206803 5.6843419E-14,14.127608 0.062010996,2.0027046 11.158781,-0.062991121 13.43702,0.0014351187 M13.438011,33.065016 C17.148173,29.334199 19.063008,26.379023 22.00051,23.379017 25.188007,19.566519 26.749013,17.206806 26.875018,14.127613 26.813007,2.002704 15.716239,-0.062987381 13.438,0.0014388781"
181+
Fill="{TemplateBinding Foreground}"
182+
Grid.Row="0" Margin="-7,2,-8,4" />
183+
<Viewbox Grid.Row="0" Width="25"
184+
Margin="-7,-6,-7,0"
185+
HorizontalAlignment="Center"
186+
VerticalAlignment="Center"
187+
Stretch="Uniform">
188+
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Slider}, Path=Value}"
189+
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"
190+
MinWidth="20" TextAlignment="Center"
191+
FontWeight="Normal" FontSize="11"/>
192+
</Viewbox>
193+
</Grid>
194+
<Viewbox.RenderTransform>
189195
<TransformGroup>
190196
<ScaleTransform ScaleX="0" ScaleY="0" />
191197
<TranslateTransform Y="4" />
@@ -363,11 +369,16 @@
363369
<Path Data="M33.065002,13.437011 C29.334181,9.7268463 26.379009,7.812011 23.379009,4.874511 19.566509,1.687011 17.206803,0.12600673 14.127608,5.6843419E-14 2.0027046,0.062010996 -0.062991121,11.158781 0.0014351187,13.43702 M33.065016,13.438011 C29.334199,17.148173 26.379023,19.063008 23.379017,22.00051 19.566519,25.188007 17.206806,26.749013 14.127613,26.875018 2.002704,26.813007 -0.062987381,15.716239 0.0014388781,13.438"
364370
Fill="{TemplateBinding Foreground}"
365371
Grid.Row="0" Margin="-2,-7,6,-8" />
366-
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Slider}, Path=Value}" Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"
367-
HorizontalAlignment="Center" VerticalAlignment="Center"
368-
FontWeight="Normal" FontSize="11"
369-
Margin="-8 -7 8 -7"/>
370-
</Grid>
372+
<Viewbox Grid.Row="0" Width="25"
373+
Margin="-8 -7 8 -7"
374+
HorizontalAlignment="Center" VerticalAlignment="Center">
375+
<TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Slider}, Path=Value}"
376+
Foreground="{DynamicResource PrimaryHueMidForegroundBrush}"
377+
MinWidth="20"
378+
TextAlignment="Center"
379+
FontWeight="Normal" FontSize="11"/>
380+
</Viewbox>
381+
</Grid>
371382
<Viewbox.RenderTransform>
372383
<TransformGroup>
373384
<ScaleTransform ScaleX="0" ScaleY="0" />

0 commit comments

Comments
 (0)