質問するログイン新規登録

質問編集履歴

1

サンプルコードを修正

2016/10/27 00:18

投稿

dekag
dekag

スコア8

title CHANGED
File without changes
body CHANGED
@@ -20,8 +20,22 @@
20
20
  ###該当のソースコード
21
21
  試したこと で作成したテキストボックスのスタイル
22
22
  ```XAML
23
+ <Window x:Class="WPFTextBoxValidation.MainWindow"
24
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
25
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
26
+ xmlns:converter="clr-namespace:Emr.Themes.Converters"
27
+ Title="www.CodeArsenal.net"
28
+ Height="240" Width="350">
29
+
30
+ <Window.Resources>
31
+ <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
32
+ <converter:SizeVisiblityConverter x:Key="SizeVisiblityConverter" />
33
+ <Style TargetType="{x:Type Label}">
34
+ <Setter Property="Margin" Value="5,0,5,0" />
35
+ <Setter Property="HorizontalAlignment" Value="Left" />
36
+ </Style>
23
37
  <Style TargetType="{x:Type TextBox}">
24
- <Setter Property="MinHeight" Value="20" />
38
+ <Setter Property="MinHeight" Value="0" />
25
39
  <Setter Property="VerticalAlignment" Value="Center" />
26
40
  <Setter Property="Margin" Value="0,2,40,2" />
27
41
  <Setter Property="Validation.ErrorTemplate">
@@ -29,17 +43,47 @@
29
43
  <ControlTemplate>
30
44
  <DockPanel LastChildFill="true">
31
45
  <Border Background="OrangeRed" DockPanel.Dock="right" Margin="5,0,0,0" Width="20" Height="20" CornerRadius="5"
32
- ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight, Converter={StaticResource SizeVisiblityConverter}}">
33
- <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white" Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight, Converter={StaticResource SizeVisiblityConverter}}" />
46
+ ToolTip="{Binding ElementName=customAdorner, Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"
47
+ Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight , Converter={StaticResource SizeVisiblityConverter}}">
48
+ <TextBlock Text="!" VerticalAlignment="center" HorizontalAlignment="center" FontWeight="Bold" Foreground="white"
49
+ Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight , Converter={StaticResource SizeVisiblityConverter}}" />
34
50
  </Border>
35
51
  <AdornedElementPlaceholder Name="customAdorner" VerticalAlignment="Center">
52
+ <Border BorderBrush="Red" BorderThickness="1"
36
- <Border BorderBrush="Red" BorderThickness="1" Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight, Converter={StaticResource SizeVisiblityConverter}}"/>
53
+ Visibility="{Binding ElementName=customAdorner, Path=AdornedElement.ActualHeight , Converter={StaticResource SizeVisiblityConverter}}"/>
37
54
  </AdornedElementPlaceholder>
38
55
  </DockPanel>
39
56
  </ControlTemplate>
40
57
  </Setter.Value>
41
58
  </Setter>
42
59
  </Style>
60
+ </Window.Resources>
61
+
62
+ <Grid x:Name="grid_EmployeeData" Margin="0,0,0,100">
63
+ <Grid.CommandBindings>
64
+ <CommandBinding Command="New" CanExecute="Confirm_CanExecute" Executed="Confirm_Executed" />
65
+ </Grid.CommandBindings>
66
+ <Grid.RowDefinitions>
67
+ <RowDefinition Height="20"/>
68
+ <RowDefinition Height="20"/>
69
+ <RowDefinition Height="20"/>
70
+ <RowDefinition Height="20"/>
71
+ </Grid.RowDefinitions>
72
+
73
+ <TextBox x:Name="textBox_Name" Grid.Row="0" Validation.Error="Validation_Error"
74
+ Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Name,
75
+ ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
76
+ <TextBox x:Name="textBox_Position" Grid.Row="1" Validation.Error="Validation_Error"
77
+ Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Position,
78
+ ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
79
+ <TextBox x:Name="textBox_Salary" Grid.Row="2" Width="50" HorizontalAlignment="left"
80
+ Validation.Error="Validation_Error" MaxLength="5"
81
+ Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Salary,
82
+ ValidatesOnDataErrors=true, NotifyOnValidationError=true}"/>
83
+ <Button Content="Confirm" Grid.Row="3" Margin="0,0,10,0"
84
+ HorizontalAlignment="right" VerticalAlignment="Center" Command="New"/>
85
+ </Grid>
86
+ </Window>
43
87
  ```
44
88
 
45
89
  ###補足情報(言語/FW/ツール等のバージョンなど)