我有一个继承自Conductor<T>.Collection.OneActive
的ViewModel。在视图中,我将DataGrid
绑定到Items
属性,将ContentControl
绑定到ActiveItem
。
<ContentControl x:Name="ActiveItem" DockPanel.Dock="Top"/>
<DataGrid x:Name="Items" AutoGenerateColumns="False" SelectionMode="Single" DockPanel.Dock="Top"
cal:Message.Attach="[Event MouseDoubleClick] = [Action test]">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding CountryCode}" Width="10*"/>
<DataGridTextColumn Binding="{Binding Country}" Width="90*" />
</DataGrid.Columns>
</DataGrid>
</ContentControl>
它运行正常,除了一件事:当Grid的一行是DoubleClicked时,我想激活DetailsViewModel
。我的void test()
方法调用得很好,但我无法禁用Click方法。
有什么建议吗?
修改
也许我不够清楚。我的问题是Conductor<T>
的默认行为。它不应该激活左键单击的详细信息屏幕,而是激活双倍。
编辑2
通过Nkosi
的帮助终于找到了一些解决方法:
只需将ContentControl绑定从ActiveItem
更改为ActiveScreen
。
<ContentControl x:Name="ActiveScreen" DockPanel.Dock="Top"/>
在ViewModel中创建了ActiveScreen
属性:
private T mActiveScreen;
public T ActiveScreen
{
get { return mActiveScreen; }
set
{
mActiveScreen = value;
NotifyOfPropertyChange(() => ActiveScreen);
}
}
在MouseDoubleClick
的绑定方法中,您只需将ActiveScreen
设置为ActiveItem
。
public void test()
{
ActiveScreen = ActiveItem;
}
答案 0 :(得分:2)
Caliburn有一个动作防护功能,其中Can{MethodName}
充当要调用的动作的守卫。它可以是属性或其他方法,一旦遵循惯例。
所以给出
public void test() { ... }
它的后卫看起来像
public bool Cantest {
get { return //..what ever is the condition needed to allow/disable action
}
或
public bool Cantest() {
return //..what ever is the condition needed to allow/disable action
}
Caliburn documentation - All About Actions
需要注意的另一个重要特征是行动警卫。当处理程序是 找到“SayHello”消息,它将检查是否该类 还有一个名为“CanSayHello”的属性或方法。如果你 有一个警卫财产,你的班级实施 INotifyPropertyChanged,然后框架将观察到的变化 该财产并相应地重新评估警卫。
答案 1 :(得分:0)
在Caliburn.Micro EventAggregator概念是他们的。阅读有助于你的概念
在当前viewmodel中发布消息并在DetailsViewModel中订阅 它的作品。
https://caliburnmicro.codeplex.com/wikipage?title=The%20Event%20Aggregator
和
Caliburn.Micro EventAggregator