Caliburn.Micro 禁用 ItemsControl 的默认点击事件

Caliburn.Micro disable default click event for ItemsControl

我有一个继承自 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>

工作正常,除了一件事:我想在网格的其中一行被双击时激活 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;
    }


在 Caliburn.Micro 中,EventAggregator 的概念是他们的。阅读对您有帮助的概念

在当前视图模型中发布消息并在 DetailsViewModel 中订阅。
它的作品。

https://caliburnmicro.codeplex.com/wikipage?title=The%20Event%20Aggregator

Caliburn.Micro EventAggregator

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

Another important feature to note is Action guards. When a handler is found for the “SayHello” message, it will check to see if that class also has either a property or a method named “CanSayHello.” If you have a guard property and your class implements INotifyPropertyChanged, then the framework will observe changes in that property and re-evaluate the guard accordingly.