質問編集履歴
1
サンプルコードを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,9 +42,37 @@
|
|
42
42
|
|
43
43
|
```XAML
|
44
44
|
|
45
|
+
<Window x:Class="WPFTextBoxValidation.MainWindow"
|
46
|
+
|
47
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
48
|
+
|
49
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
50
|
+
|
51
|
+
xmlns:converter="clr-namespace:Emr.Themes.Converters"
|
52
|
+
|
53
|
+
Title="www.CodeArsenal.net"
|
54
|
+
|
55
|
+
Height="240" Width="350">
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
<Window.Resources>
|
60
|
+
|
61
|
+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
62
|
+
|
63
|
+
<converter:SizeVisiblityConverter x:Key="SizeVisiblityConverter" />
|
64
|
+
|
65
|
+
<Style TargetType="{x:Type Label}">
|
66
|
+
|
67
|
+
<Setter Property="Margin" Value="5,0,5,0" />
|
68
|
+
|
69
|
+
<Setter Property="HorizontalAlignment" Value="Left" />
|
70
|
+
|
71
|
+
</Style>
|
72
|
+
|
45
73
|
<Style TargetType="{x:Type TextBox}">
|
46
74
|
|
47
|
-
<Setter Property="MinHeight" Value="
|
75
|
+
<Setter Property="MinHeight" Value="0" />
|
48
76
|
|
49
77
|
<Setter Property="VerticalAlignment" Value="Center" />
|
50
78
|
|
@@ -60,15 +88,21 @@
|
|
60
88
|
|
61
89
|
<Border Background="OrangeRed" DockPanel.Dock="right" Margin="5,0,0,0" Width="20" Height="20" CornerRadius="5"
|
62
90
|
|
63
|
-
ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
|
91
|
+
ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
|
64
92
|
|
65
|
-
|
93
|
+
Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight , Converter={StaticResource SizeVisiblityConverter}}">
|
94
|
+
|
95
|
+
<TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white"
|
96
|
+
|
97
|
+
Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight , Converter={StaticResource SizeVisiblityConverter}}" />
|
66
98
|
|
67
99
|
</Border>
|
68
100
|
|
69
101
|
<AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center">
|
70
102
|
|
103
|
+
<Border BorderBrush="Red" BorderThickness="1"
|
104
|
+
|
71
|
-
|
105
|
+
Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight , Converter={StaticResource SizeVisiblityConverter}}"/>
|
72
106
|
|
73
107
|
</AdornedElementPlaceholder>
|
74
108
|
|
@@ -82,6 +116,60 @@
|
|
82
116
|
|
83
117
|
</Style>
|
84
118
|
|
119
|
+
</Window.Resources>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<Grid x:Name="grid_EmployeeData" Margin="0,0,0,100">
|
124
|
+
|
125
|
+
<Grid.CommandBindings>
|
126
|
+
|
127
|
+
<CommandBinding Command="New" CanExecute="Confirm_CanExecute" Executed="Confirm_Executed" />
|
128
|
+
|
129
|
+
</Grid.CommandBindings>
|
130
|
+
|
131
|
+
<Grid.RowDefinitions>
|
132
|
+
|
133
|
+
<RowDefinition Height="20"/>
|
134
|
+
|
135
|
+
<RowDefinition Height="20"/>
|
136
|
+
|
137
|
+
<RowDefinition Height="20"/>
|
138
|
+
|
139
|
+
<RowDefinition Height="20"/>
|
140
|
+
|
141
|
+
</Grid.RowDefinitions>
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
<TextBox x:Name="textBox_Name" Grid.Row="0" Validation.Error="Validation_Error"
|
146
|
+
|
147
|
+
Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Name,
|
148
|
+
|
149
|
+
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
|
150
|
+
|
151
|
+
<TextBox x:Name="textBox_Position" Grid.Row="1" Validation.Error="Validation_Error"
|
152
|
+
|
153
|
+
Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Position,
|
154
|
+
|
155
|
+
ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
|
156
|
+
|
157
|
+
<TextBox x:Name="textBox_Salary" Grid.Row="2" Width="50" HorizontalAlignment="left"
|
158
|
+
|
159
|
+
Validation.Error="Validation_Error" MaxLength="5"
|
160
|
+
|
161
|
+
Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Salary,
|
162
|
+
|
163
|
+
ValidatesOnDataErrors=true, NotifyOnValidationError=true}"/>
|
164
|
+
|
165
|
+
<Button Content="Confirm" Grid.Row="3" Margin="0,0,10,0"
|
166
|
+
|
167
|
+
HorizontalAlignment="right" VerticalAlignment="Center" Command="New"/>
|
168
|
+
|
169
|
+
</Grid>
|
170
|
+
|
171
|
+
</Window>
|
172
|
+
|
85
173
|
```
|
86
174
|
|
87
175
|
|