How can you add a value constraint to a a XamMultiColumnComboEditor ? It doesn't implement ValueEditor, so you cant apply as you would with a XamComboEditor...
var style = new Style(typeof(XamComboEditor)); style.Setters.Add(new Setter(ValueEditor.ValueConstraintProperty, constraint)); return new UnboundField { Settings = { EditorType = style.TargetType, EditorStyle = style } };
Is it possible to do similar with a XamMultiColumnComboEditor ?
Cheers
Jonathan
Hi Jonathan,
It doesn't look like it's possible to use ValidationRules for SelectedItems. SelectedItems is a collection type therefore the binding to your view model property won't be updating very much. Instead the combo editor will just add and remove elements as required and this does not update the binding from target to source so no validation will occur. In this case using IDataErrorInfo or INotifyDataErrorInfo would be a better option. These interfaces are data side validation that is done in your view model on the various properties. Microsoft has a topic about it here:https://social.technet.microsoft.com/wiki/contents/articles/19490.wpf-4-5-validating-data-in-using-the-inotifydataerrorinfo-interface.aspx
The idea is that your view model collection that is bound to SelectedItems will handle the CollectionChanged event and when this event fires you validate the new data and add the appropriate errors. Then you notify any UI elements that are bound to the associated property that there is an error and it will display the red border.
Ok thanks, this works for the SelectedItem, now how to do the same for SelectedItems please?
I did some digging into the XamMultiColumnComboEditor and it doesn't look like we provide any simple way to make sure that values aren't allowed to be null. There are, however, a number of ways that WPF provides similar functionality. For example, ValidationRules are something you can try which validate user input before it updates the binding source. They provide the same red outline and they also provide a tooltip which can contain an error message if you provide one. ValidationRules are also fairly easy to implement. Just create a custom ValidationRule class and then hook it up on your bindings in XAML.
public class MyValidationRule : ValidationRule { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { if (value == null) return new ValidationResult(false, "Selected item can't be null");
return new ValidationResult(true, null); } } <ig:XamMultiColumnComboEditor ItemsSource="{Binding Data}"> <ig:XamMultiColumnComboEditor.SelectedItem> <Binding Path="Item"> <Binding.ValidationRules> <local:MyValidationRule/> </Binding.ValidationRules> </Binding> </ig:XamMultiColumnComboEditor.SelectedItem> </ig:XamMultiColumnComboEditor>
We'd ideally like the same behaviour that the XamComboBox has. On the XamComboBox we can give it a...
new ValueConstraint {Nullable = false}
This will then ensure that the combobox has a value and if not it shows a little red asterix and decorates the combobox with a red outline.
if this is achievable some other way it would be great.
There are currently two kinds of combo editors in the WPF product. One kind is the XamComboEditor that exists inside the Infragistics.Windows.Editors namespace. This is the editor that derives off of ValueEditor and contains the ValueConstraint property. The other kind is the XamMultiColumnComboEditor and XamComboEditor that exist inside the Infragistics.Controls.Editors namespace. These controls were originally created to support both Silverlight and WPF and are a separate set of controls. These do not derive from ValueEditor so they do not have a ValueConstraint.
What kind of constraint are you trying to implement on XamMultiColumnComboEditor? Maybe there is a different way to implement it other than a ValueConstraint.