验证和多重绑定问题 [英] Problem with validation and multibinding

查看:72
本文介绍了验证和多重绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my WPF application I use the following 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并未注意到它.我有一个定义有错误模板的样式,当文本框中出现任何错误时都应应用该样式.我想也许多重绑定是不允许这种情况的,因为在我使用单一绑定的情况下一切正常.

The view model class which the first binding uses implements IDataErrorInfo for validation purposes. The problem is that although the error is caught in the property setter, the UI doesn't notice it. I have a style defined with an error template which should be applied when any error occurs in the text box. I suppose that maybe this scenario is not allowed with multi binding because where I use single binding everything works fine.

先谢谢了.

推荐答案

在我看来,没有人知道这个答案,但是我认为这种情况是行不通的.如果有人需要它,我会尽力回答.我试图将我的View绑定到实现IDataErrorInfo的View Model类,在xaml中,我指定了一个转换器,尽管一切正常,但Errors并未显示在UI上.因此,我从绑定中删除了转换器,并在视图模型中实现了该逻辑,瞧,现在一切正常.

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.

这篇关于验证和多重绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆