我想在使用Caliburn.Micro的WPF应用程序中使用来自Fluent功能区控件的DropDownButton。WPF功能区:DropDownButton + Caliburn.Micro事件
到目前为止,一切都很好。我在DropDownButton中看到我的Unicorns列表为GalleryItems。 唯一的问题是我无法得到“ShowUnicorn()”的工作。 当我点击DropDownButton列表中的一个项目时,它什么都不做。 我做错了什么?
这是我使用的代码:
<Fluent:DropDownButton Header="Farm"
LargeIcon="..\..\Resources\unicorn48.png">
<Fluent:Gallery ItemsSource="{Binding AllUnicorns}">
<Fluent:Gallery.ItemTemplate>
<DataTemplate>
<Fluent:GalleryItem Content="{Binding UnicornFoobar}"
cal:Message.Attach="[Event Click] = [Action ShowUnicorn()]" />
</DataTemplate>
</Fluent:Gallery.ItemTemplate>
</Fluent:Gallery>
在此先感谢。
我认为这是旧的DataTemplate问题 - 对于这个漂浮在SO上的问题有几个答案,但通常需要将'cal:Action.TargetWithoutContext'绑定到ViewModel。基本上发生的情况是,每行的'DataContext'就是实际的数据项本身(不是虚拟机),当你点击时,CM正试图解决数据项的方法。您需要告诉CM您希望使用操作而不是虚拟机中的数据行来定位虚拟机。 – Charleh