开发者

WPF TexBox TwoWay Binding Problem when ValidationRules used

I seem to hav开发者_如何学JAVAe a problem with TwoWay DataBinding - my application has a window with a bunch of textboxes that allow to edit values of the properties they are bound to. Everything works well except for textboxes that also have a validation rule defined, in which case no text is displayed in the textbox when the window opens (binding back-to-source still works fine for those). If I remove Validation rule, everything's back to normal. I searched for an answer to this for a few hours now, but somehow did not even find anyone else complaining of the same issue. I am completely new to WPF, and I am sure it is just a silly mistake I have somewhere in my code... I will greatly appreciate any feedback...

<TextBox Margin="40,2,20,0" Grid.Column="0" Grid.Row="1" Background="#99FFFFFF" >
        <Binding Path="LastName" Mode="TwoWay" ValidatesOnDataErrors="true" UpdateSourceTrigger="LostFocus" >
                    <Binding.ValidationRules>
                        <validation:StringNameValidationRule />
                    </Binding.ValidationRules>
        </Binding>
</TextBox>


It would be nice to know what your binding source is, does it implement INotifyPropertyChanged for example?

Without nothing that, the only thing I can think of is the NotifyOnValidationError property on the binding class. Try setting it to true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜