1
多くのテキストボックスを持つフォームがあり、それぞれに同じ検証エラーテンプレートが必要です。 今、私はすべてのテキストボックスに対してこれらの検証エラーテンプレートを書いてはいけません。だから、どこに置かなければならないので、すべてのテキストボックスが影響を受けますか? Validation.ErrorTemplateとWPF - アプリケーション内のすべてのテキストボックス用のカスタムErrorTemplate
テキストボックス:
<TextBox x:Name="textBox3" TextWrapping="Wrap" Height="23" Text="{Binding User_Id, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}" VerticalAlignment="Top">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel>
<AdornedElementPlaceholder x:Name="textBox"/>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ErrorContent}" Foreground="Red"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</TextBox>
マイCustomControl:
public class ValidationTextBox : TextBox
{
static ValidationTextBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ValidationTextBox), new FrameworkPropertyMetadata(typeof(ValidationTextBox)));
//Validation.SetErrorTemplate(new ValidationTextBox(),)
}
public ValidationTextBox() { }
}
私app.xaml(Application.Ressources)にそれを置きます。それはうまくいきました。 :)カスタムコントロールは必要ありません。 – lordnik22