Skip to content

Commit 24124f4

Browse files
committed
Remove width constraint when using popup for validation errors. fixes #406
1 parent 740d229 commit 24124f4

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

MainDemo.Wpf/TextFields.xaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:domain="clr-namespace:MaterialDesignColors.WpfExample.Domain"
77
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
8-
xmlns:materialDesignDemo="clr-namespace:MaterialDesignDemo"
98
xmlns:domain1="clr-namespace:MaterialDesignDemo.Domain"
109
mc:Ignorable="d"
1110
d:DesignHeight="300" d:DesignWidth="600" Loaded="UserControl_Loaded"
@@ -225,5 +224,19 @@
225224
</domain1:SimpleDataTemplateSelector>
226225
</ContentControl.ContentTemplateSelector>
227226
</ContentControl>
227+
<TextBlock Grid.Row="7" Grid.Column="4" Style="{StaticResource MaterialDesignSubheadingTextBlock}"
228+
Margin="0 48 0 0">Tight Space Validation</TextBlock>
229+
<TextBox Grid.Row="8" Grid.Column="4" Width="20"
230+
materialDesign:ValidationAssist.UsePopup="True"
231+
HorizontalAlignment="Left"
232+
ToolTip="Use a popup which can escape the bounds of the control where space is limited">
233+
<TextBox.Text>
234+
<Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
235+
<Binding.ValidationRules>
236+
<domain1:NotEmptyValidationRule ValidatesOnTargetUpdated="True" />
237+
</Binding.ValidationRules>
238+
</Binding>
239+
</TextBox.Text>
240+
</TextBox>
228241
</Grid>
229242
</UserControl>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ValidationErrorTemplate.xaml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,42 @@
88
<ControlTemplate.Resources>
99
<DataTemplate DataType="{x:Type ValidationError}">
1010
<TextBlock Foreground="{DynamicResource ValidationErrorBrush}"
11-
FontSize="10"
12-
MaxWidth="{Binding ElementName=Placeholder, Path=ActualWidth}"
13-
HorizontalAlignment="Left"
14-
Margin="2"
15-
TextWrapping="Wrap"
16-
Text="{Binding ErrorContent}"
17-
UseLayoutRounding="false" />
11+
FontSize="10"
12+
MaxWidth="{Binding ElementName=Placeholder, Path=ActualWidth}"
13+
HorizontalAlignment="Left"
14+
Margin="2"
15+
TextWrapping="Wrap"
16+
Text="{Binding ErrorContent}"
17+
UseLayoutRounding="false" />
1818
</DataTemplate>
1919
</ControlTemplate.Resources>
2020
<StackPanel>
2121
<AdornedElementPlaceholder Name="Placeholder" />
2222
<Border Name="DefaultErrorViewer"
2323
Visibility="Collapsed"
2424
Background="{DynamicResource MaterialDesignPaper}">
25-
<ContentPresenter Content="{Binding CurrentItem}" />
25+
<TextBlock Foreground="{DynamicResource ValidationErrorBrush}"
26+
FontSize="10"
27+
MaxWidth="{Binding ElementName=Placeholder, Path=ActualWidth}"
28+
HorizontalAlignment="Left"
29+
Margin="0 2"
30+
TextWrapping="Wrap"
31+
Text="{Binding CurrentItem.ErrorContent}"
32+
UseLayoutRounding="false" />
2633
</Border>
27-
2834
<controlzEx:PopupEx x:Name="ValidationPopup"
29-
IsOpen="False"
30-
Placement="Bottom"
31-
PlacementTarget="{Binding ElementName=Placeholder, Mode=OneWay}"
32-
AllowsTransparency="True">
35+
IsOpen="False"
36+
Placement="Bottom"
37+
PlacementTarget="{Binding ElementName=Placeholder, Mode=OneWay}"
38+
AllowsTransparency="True">
3339
<Border Background="{DynamicResource MaterialDesignPaper}">
34-
<ContentPresenter Content="{Binding CurrentItem}" />
40+
<TextBlock Foreground="{DynamicResource ValidationErrorBrush}"
41+
FontSize="10"
42+
HorizontalAlignment="Left"
43+
Margin="0 2"
44+
TextWrapping="Wrap"
45+
Text="{Binding CurrentItem.ErrorContent}"
46+
UseLayoutRounding="false" />
3547
</Border>
3648
</controlzEx:PopupEx>
3749
</StackPanel>

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Comphrehensive and easy to use Material Design theme and control library for the
2222
[![NuGet-Themes](https://img.shields.io/nuget/dt/MaterialDesignColors.svg?label=NuGet-Colors&style=flat-square)](https://www.nuget.org/packages/MaterialDesignColors/)
2323
[![Issues](https://img.shields.io/github/issues/ButchersBoy/MaterialDesignInXamlToolkit.svg?style=flat-square)](https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/issues)
2424
[![Twitter](https://img.shields.io/badge/twitter-%40james__willock-55acee.svg?style=flat-square)](https://twitter.com/James_Willock)
25-
25+
2626
# ![Alt text](web/images/MD4XAML28.png "How Can I Use The Themes?") How Can I Use The Themes?
2727

2828
* Checkout the [Super Quick Start](https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/wiki/Super-Quick-Start)
@@ -35,6 +35,7 @@ To load the source project you will need Visual Studio 2015. Don't worry if you
3535

3636
* Download the source and run the demo.
3737
* Checkout [F1ix](http://materialdesigninxaml.net/f1ix).
38+
* Checkout [Motion List](https://github.com/MaterialDesignInXAML/MotionList).
3839

3940
# ![Alt text](web/images/MD4XAML28.png "Contributions") Contribution Guidelines
4041

0 commit comments

Comments
 (0)