これはxamlの私のコードです。このエラーが発生し続けます」 添付可能なプロパティ 'Resources' がタイプ 'Grid' で見つかりませんでした。また、それに伴って local:AgeValidation - not found が表示されます。助けてください。ありがとうございます。
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid.Resources> <Style TargetType="{x:Type TextBox}"> <Style.Triggers> <Trigger Property="Validation.HasError" Value ="true"> <Setter Property="ToolTip" Value="{Binding RelativeSource ={x:Static RelativeSource.Self}, Path= (Validation.Errors)[0].ErrorContent}"/> </Trigger> </Style.Triggers> <Setter Property="Validation.ErrorTemplate"> <Setter.Value> <ControlTemplate> <DockPanel DockPanel.Dock="Right"> <AdornedElementPlaceholder> <Border BorderBrush="Red" BorderThickness="2"/> </AdornedElementPlaceholder> <TextBlock Margin=" 3" Text=" *" Foreground="Red" ToolTip="{Binding Path= AdornedElement.ToolTip, RelativeSource= {RelativeSource Mode=FindAncestor, AncestorType={x:Type Adorner}}}"/> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="x:Type Button}"> <Style.Triggers> <DataTrigger Binding="Binding ElementName= txtAge, Path= (Validation.HasError)}" Value=" True"> <Setter Property="IsEnabled" Value=" False"/> </DataTrigger> <DataTrigger Binding="Binding ElementName= txtFirstName, Path=(Validation.HasError)}" Value=" True"> <Setter Property="IsEnabled" Value=" False"/> </DataTrigger> <DataTrigger Binding="Binding ElementName= txtLastName, Path= (Validation.HasError)}" Value=" True"> <Setter Property="IsEnabled" Value=" False"/> </DataTrigger> </Style.Triggers> </Style> <TextBox Name="txtFirstName" Grid.Column=" 1" Text="{Binding Path=FirstName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors =True}" Width="150" Margin=" 5"/> <TextBlock Text="Last Name :" Margin=" 10" Grid.Row="1" /> <TextBox Name="txtLastName" Grid.Column="1" Text="Binding Path=LastName, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Grid.Row="1" Width=" 150" Margin=" 5"/> <TextBlock Text="Age : " Margin=" 10" Grid.Row="2" /> <TextBox Name="txtAge" Grid.Column="1" Grid.Row="2" Width=" 150" Margin="5"> <TextBox.Text> <Binding Path=" Age" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True"> <Binding.ValidationRules> <local:AgeValidation MinimumAge="1"/> </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox>
<Button Grid.Column="1" Grid.Row="3" Content=" Update" Margin=" 5" HorizontalAlignment="Center" /> </Grid.Resources>