wpf - Can you use ValidationRules on ListBox.SelectedItems? -
I want to use validationRules to verify that something ListBox < / Code> Select at least one item of control
I tried to do it like this:
& lt; List box itemsource = "{binding path = available item}" behavior: multi-selector attributes. Synced items selected = "{Objects to select bounded}" x: name = "ListBoxItems" & gt; & Lt; ListBox.Tag & gt; & Lt; Binding element name = "list box" path = "selected item" & gt; & Lt; Binding.ValidationRules & gt; & Lt; Validation rule: NotNullValidationRule /> & Lt; /Binding.ValidationRules> & Lt; / Binding & gt; & Lt; /ListBox.Tag> & Lt; / ListBox & gt; But my no null validation rule is never called, note that synchronized selected items is a special enclosed property I use to synchronize SelectedItems in a custom collection (code). This is the reason why I validate myself on the tag to apply the 'fake' binding instead.
Is there a way to validate ListBox.SelectedItems
Validation is done only in twofold and oneweatosource mode binding. If you change the binding around, verification has been started to tag the chosen election binding either in Doha or One-to-Source mode.
There is validation for the safety of the goal so when you set the tag, verification ensures that the tag is valid and the selected item can be set with a new value. The following code works (the chosen itam doubles automatically binds IIRC.)
& lt; ListBox x: name = "list" & gt; & Lt; ListBox.SelectedItem & gt; & Lt; Binding element name = "list" path = "tag" & gt; & Lt; Binding.ValidationRules & gt; & Lt; Local: Selected ValidationRule / & gt; & Lt; /Binding.ValidationRules> & Lt; / Binding & gt; & Lt; /ListBox.SelectedItem> & Lt; / ListBox & gt;
Comments
Post a Comment