Hello Andy H,
What I would suggest is to create an extension class and an attached proeprty that would handle this scenario without populating the rest of the code. For example:
public class TreeViewExtensions : DependencyObject
{
public static bool GetDisallowCheckOnDisabledItems(DependencyObject obj)
{
return (bool)obj.GetValue(DisallowCheckOnDisabledItemsProperty);
}
public static void SetDisallowCheckOnDisabledItems(DependencyObject obj, bool value)
{
obj.SetValue(DisallowCheckOnDisabledItemsProperty, value);
}
public static readonly DependencyProperty DisallowCheckOnDisabledItemsProperty =
DependencyProperty.RegisterAttached("DisallowCheckOnDisabledItems", typeof(bool), typeof(RadTreeView),
new PropertyMetadata(false, OnDisallowCheckOnDisabledItemsChanged));
private static void OnDisallowCheckOnDisabledItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
RadTreeView owner = d as RadTreeView;
if (owner != null)
{
bool newValue = (bool)args.NewValue;
if (newValue)
{
owner.PreviewChecked += OnPreviewChecked;
}
else
{
owner.PreviewChecked -= OnPreviewChecked;
}
}
}
static void OnPreviewChecked(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;
e.Handled = item != null && !item.IsEnabled;
}
}
Applying the behavior:
Please let me know if you have questions on this matter.
All the best,
Alex Fidanov
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!