3

在我的 WPF 应用程序中,我使用以下 xaml:...

<TextBox
services:TextBoxService.IsFocused="{Binding Path=IsSelected, Mode=OneWay}"
FocusVisualStyle="{x:Null}">
    <MultiBinding
        Converter="{StaticResource mconv_operableToString}" 
        UpdateSourceTrigger="PropertyChanged">
            <Binding 
                Path="Value"
                Mode="TwoWay"
                NotifyOnValidationError="True" />
            <Binding 
                RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" 
                Path="DataContext.Status"
                Mode="OneWay" />
     </MultiBinding>

第一个绑定使用的视图模型类实现 IDataErrorInfo 以进行验证。问题是,虽然错误在属性设置器中被捕获,但 UI 并没有注意到它。我有一个用错误模板定义的样式,当文本框中发生任何错误时应该应用该样式。我想也许这种情况在多重绑定中是不允许的,因为在我使用单一绑定的地方一切正常。

提前致谢。

4

1 回答 1

3

It seems to me that nobody knows the answer to this but I suppose that this scenario just doesn't work. I'll try to answer it in case somebody will need it. I've tried to bind my View to my View Model class which implements IDataErrorInfo, in xaml I specified a converter and although everything worked fine, the Errors just didn't show up on the UI. So, I removed the converter from the binding and implemented that logic inside the View Model and, voila now everything works fine.

于 2010-06-24T13:11:11.473 回答