Validation XAML用户控件验证

Validation XAML用户控件验证,validation,xaml,user-controls,Validation,Xaml,User Controls,我有一个用户控件,它是一个文本框和两个按钮的组合。我已经设置了Dependency属性,以便它正确绑定到我的模型。问题是当我出现验证错误时,红色边框会同时包裹文本框和按钮 我想更改行为,以便在出现错误时,只有内部文本框有红色边框,但无法确定如何执行此操作 [试图发布图像,但我不够高:-] 我的文本框在用户控件中绑定了它,它被包装在带有按钮堆栈面板的网格中,因为它们是动态的 代码隐藏 private static DependencyProperty TextProperty = Dependen

我有一个用户控件,它是一个文本框和两个按钮的组合。我已经设置了Dependency属性,以便它正确绑定到我的模型。问题是当我出现验证错误时,红色边框会同时包裹文本框和按钮

我想更改行为,以便在出现错误时,只有内部文本框有红色边框,但无法确定如何执行此操作

[试图发布图像,但我不够高:-]

我的文本框在用户控件中绑定了它,它被包装在带有按钮堆栈面板的网格中,因为它们是动态的

代码隐藏

private static DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UserControl));
XAML文件

<Textbox Grid.Column="0"
         Text="{Binding Text, Mode=TwoWay, StringFormat={StaticResource CommaFormat}
            , RelativeSource={RelativeSource FindAncestor
            , AncestorType={x:Type UserControl}}, ValidatesOnDataErrors=True}"
         x:Name="txt" 
         MaxLength="6" Height="22" Width="65" VerticalAlignment="Top" />
以我的主要形式。。我有这个xaml绑定

<WeightTextbox Grid.Column="1" Grid.Row="2" Margin="5,0"
               Text="{Binding SelectedDocument.Weight1,
                      Mode=TwoWay,
                      ValidatesOnDataErrors=True,
                      TargetNullValue={x:Static sys:String.Empty}}" />
注意:这在单个windows窗体上出现5次,以便我可以为文档收集不同的权重

我试过搜索,但什么也没找到

最后编辑足够高的rep以添加图像

昨天终于有了一个哈哈的时刻,所以我发布了这个帖子,以防有人来搜索。在我的WeightTextbox中添加了一个名为Required的依赖项属性

  private static DependencyProperty RequiredProperty = DependencyProperty.Register("Required", typeof(bool), typeof(xagDateTimeCustom));

    public Boolean Required
    {
        get
        {
            return (bool)GetValue(RequiredProperty);
        }
        set
        {
            bool oldValue = Required;
            SetValue(RequiredProperty, value);
            DependencyPropertyChangedEventArgs e = new DependencyPropertyChangedEventArgs(RequiredProperty, oldValue, value);
            OnPropertyChanged(e);
        }
    }
在我的主要表格中,我现在做以下工作。。正在设置新的必需属性,并且ValidateSondaErrors设置为False

<WeightTextbox Grid.Column="1" Grid.Row="2" Margin="5,0"
               Required=True
               Text="{Binding SelectedDocument.Weight1,
                      Mode=TwoWay,
                      ValidatesOnDataErrors=False,
                      TargetNullValue={x:Static sys:String.Empty}}" />
然后在我的自定义控件中,我实现了IDataErrorInfo,它现在似乎可以工作了


有人能给我指出正确的方向吗。任何帮助都将不胜感激。