Problem with validation and multibinding

南笙酒味 提交于 2019-12-12 14:29:03

问题


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>

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.

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/3052150/problem-with-validation-and-multibinding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!