【发布时间】:2010-08-29 01:13:23
【问题描述】:
我正在尝试做类似于this 问题中的人想要做的事情。
是否有任何比那里建议的解决方法更优雅的方法来做到这一点?
(作为最后的手段)是否有不同的 mvvm 框架可以更好地支持这样做?
现在我正在尝试制作一个继承自树视图的自定义控件,如下所示:
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);
}
然后我会将我想要触发的命令绑定到 ItemCollapsedCommand 依赖属性。然而,即使这样也行不通。
我不断收到InvalidOperationException:
“调度程序处理已暂停,但仍在处理消息。”
有什么想法吗?
【问题讨论】:
标签: c# wpf mvvm-light treeviewitem