I have a treeview in WPF and I bind the nodes via caliburn micro from a viewmodel.
I want to set a simple validation: when no node is selected, the treeview should be in error state and show a message, else not. For other controls like textbox or combobox I just set the validation properties in the view while binding and implement the IDataErrorInfo interface for the viewmodel. But I have no idea how to do this with the treeview.
My approach until now:
I create a validation rule for the tree to check if a treeview node is selected. The rule is executed, and seems to work, but I don't know how to activate validation in the Xaml. How do I activate validation for the treeview?
View:
<TreeView Name="Items" />
ViewModel:
public List<TreeViewItem> Items
{
get { return mItems; }
set
{
mItems= value;
NotifyOfPropertyChange(() => Items);
}
}
public string this[string columnName]
{
get
{
if ((columnNames == "Items") && !Items.Any(x => x.IsSelected))
{
return "Error..";
}
...
}
}