I am trying to do something similar to what the person in this question wanted to do.
Is there any, more elegant, way to do this than the work-around suggested there?
(As a last resort) Is there a different mvvm framework that would have better support for doing this?
Right now I'm trying to make a custom control that inherits from the treeview, like this:
public ModdedTreeView()
{
this.AddHandler(TreeViewItem.CollapsedEvent, new RoutedEventHandler(ItemCollapsed));
}
public RelayCommand<RoutedEventArgs> ItemCollapsedCommand
{
get { return (RelayCommand<RoutedEventArgs>)GetValue(ItemCollapsedCommandProperty); }
set { SetValue(ItemCollapsedCommandProperty, value); }
}
// Using a DependencyProperty as the backing store for ItemCollapsedCommand. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ItemCollapsedCommandProperty =
DependencyProperty.Register("ItemCollapsedCommand", typeof(RelayCommand<RoutedEventArgs>), typeof(ModdedTreeView), new UIPropertyMetadata(null));
protected void ItemCollapsed(object sender, RoutedEventArgs e)
{
if (ItemCollapsedCommand != null)
ItemCollapsedCommand.Execute(e);
}
I would then bind the command I want to fire, to the ItemCollapsedCommand dependancy property. However even this is not working.
I keep getting an InvalidOperationException
:
"Dispatcher processing has been suspended, but messages are still being processed."
Any ideas?