Skip to content

Commit b932e4c

Browse files
rrsKeboo
authored andcommitted
can now use ValidationAssist to set the popup placement (#1180)
1 parent 14bfcf2 commit b932e4c

File tree

4 files changed

+59
-12
lines changed

4 files changed

+59
-12
lines changed

MainDemo.Wpf/Domain/TextFieldsViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace MaterialDesignColors.WpfExample.Domain
88
public class TextFieldsViewModel : INotifyPropertyChanged
99
{
1010
private string _name;
11+
private string _name2;
1112
private int? _selectedValueOne;
1213
private string _selectedTextTwo;
1314

@@ -28,6 +29,15 @@ public string Name
2829
}
2930
}
3031

32+
public string Name2
33+
{
34+
get { return _name2; }
35+
set
36+
{
37+
this.MutateVerbose(ref _name2, value, RaisePropertyChanged());
38+
}
39+
}
40+
3141
public int? SelectedValueOne
3242
{
3343
get { return _selectedValueOne; }

MainDemo.Wpf/TextFields.xaml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,37 @@
307307
</smtx:XamlDisplay>
308308
<TextBlock Grid.Row="7" Grid.Column="4" Style="{StaticResource MaterialDesignSubheadingTextBlock}"
309309
Margin="0 48 0 0">Tight Space Validation</TextBlock>
310-
<smtx:XamlDisplay Key="fields_22" Grid.Row="8" Grid.Column="4" HorizontalAlignment="Left">
311-
<TextBox Width="20"
310+
<StackPanel Orientation="Horizontal" Grid.Row="8" Grid.Column="4">
311+
<smtx:XamlDisplay Key="fields_22" HorizontalAlignment="Left">
312+
<TextBox Width="20"
312313
materialDesign:ValidationAssist.UsePopup="True"
313314
HorizontalAlignment="Left"
314315
ToolTip="Use a popup which can escape the bounds of the control where space is limited">
315-
<TextBox.Text>
316-
<Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
317-
<Binding.ValidationRules>
318-
<domain1:NotEmptyValidationRule ValidatesOnTargetUpdated="True" />
319-
</Binding.ValidationRules>
320-
</Binding>
321-
</TextBox.Text>
322-
</TextBox>
323-
</smtx:XamlDisplay>
316+
<TextBox.Text>
317+
<Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
318+
<Binding.ValidationRules>
319+
<domain1:NotEmptyValidationRule ValidatesOnTargetUpdated="True" />
320+
</Binding.ValidationRules>
321+
</Binding>
322+
</TextBox.Text>
323+
</TextBox>
324+
</smtx:XamlDisplay>
325+
<smtx:XamlDisplay Key="fields_30" Grid.Row="8" Grid.Column="5" HorizontalAlignment="Left">
326+
<TextBox Width="20"
327+
materialDesign:ValidationAssist.UsePopup="True"
328+
materialDesign:ValidationAssist.PopupPlacement="Left"
329+
HorizontalAlignment="Left"
330+
ToolTip="Use a popup which can escape the bounds of the control where space is limited it can be placed in alternative positions">
331+
<TextBox.Text>
332+
<Binding Path="Name2" UpdateSourceTrigger="PropertyChanged">
333+
<Binding.ValidationRules>
334+
<domain1:NotEmptyValidationRule ValidatesOnTargetUpdated="True" />
335+
</Binding.ValidationRules>
336+
</Binding>
337+
</TextBox.Text>
338+
</TextBox>
339+
</smtx:XamlDisplay>
340+
</StackPanel>
324341
<smtx:XamlDisplay Key="fields_23" Grid.Row="9" Grid.Column="4" Grid.RowSpan="2" HorizontalAlignment="Left">
325342
<StackPanel>
326343
<CheckBox x:Name="DisplaySelectedItemCheckBox"

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.ValidationErrorTemplate.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
</Border>
3434
<controlzEx:PopupEx x:Name="ValidationPopup"
3535
IsOpen="False"
36-
Placement="Bottom"
36+
Placement="{Binding ElementName=Placeholder, Path=AdornedElement.(wpf:ValidationAssist.PopupPlacement)}"
3737
PlacementTarget="{Binding ElementName=Placeholder, Mode=OneWay}"
3838
AllowsTransparency="True">
3939
<Border x:Name="PopupBorder" Background="{Binding ElementName=Placeholder, Path=AdornedElement.(wpf:ValidationAssist.Background)}">

MaterialDesignThemes.Wpf/ValidationAssist.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Windows;
2+
using System.Windows.Controls.Primitives;
23
using System.Windows.Media;
34

45
namespace MaterialDesignThemes.Wpf
@@ -51,6 +52,25 @@ public static void SetUsePopup(DependencyObject element, bool value)
5152

5253
#endregion
5354

55+
/// <summary>
56+
/// The hint property
57+
/// </summary>
58+
public static readonly DependencyProperty PopupPlacementProperty = DependencyProperty.RegisterAttached(
59+
"PopupPlacement",
60+
typeof(PlacementMode),
61+
typeof(ValidationAssist),
62+
new FrameworkPropertyMetadata(PlacementMode.Bottom, FrameworkPropertyMetadataOptions.Inherits));
63+
64+
public static PlacementMode GetPopupPlacement(DependencyObject element)
65+
{
66+
return (PlacementMode)element.GetValue(UsePopupProperty);
67+
}
68+
69+
public static void SetPopupPlacement(DependencyObject element, PlacementMode value)
70+
{
71+
element.SetValue(UsePopupProperty, value);
72+
}
73+
5474
/// <summary>
5575
/// Framework use only.
5676
/// </summary>

0 commit comments

Comments
 (0)