繁体   English   中英

命令绑定只能在Designer / VS中使用,而不能在build / release中使用

[英]Command Binding works in designer/VS, but not build/release

我可能在这里忽略了一些显而易见的事情,但是我现在看不到它的存在。

我在用户控件(数据网格)上进行了交互,该控件具有绑定到ICollectionView的项目源,但是DataContext是从父窗口继承的:

<DataGrid Margin="0" ItemsSource="{Binding ItemsView}" AutoGenerateColumns="False" IsReadOnly="True"
          SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
    <DataGrid.Columns>
        ....
    </DataGrid.Columns>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
            <i:InvokeCommandAction Command="{Binding OnNotifyPeg}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</DataGrid>

DataContext从父窗口继承,该父窗口具有选项卡式视图:

<Window x:Class="ConfigBrowser.Views.ConfigView"
    DataContext="{Binding ConfigViewModel, Source={StaticResource Locator}}">
    <Grid Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
        <TabControl Height="Auto" Width="Auto"
                    Background="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}">
            <TabItem Header="Overview">
                <controls:Overview/>
            </TabItem>

现在,OnNotifyPeg命令仅打开一个窗口(通过服务,还有一个消息框进行调试)

public ICommand OnNotifyPeg
{
    get { return new DelegateCommand(NotifyPeg); }

}

public void NotifyPeg()
{
    MessageBox.Show("Notify peg", "Clicked");
    _detailService.ViewPeg(SelectedItem);
}

在Visual Studio中运行时,它可以正常工作-uc可以将Command触发。

但是,当我从Debug或Release文件夹运行时,什么也没发生。 没有错误,没有窗口,什么都没有-据我所知,它不是在构建的应用程序中绑定的吗?

编辑:同样要添加的是,列仍然可以从ItemSource加载其数据(使用数据上下文)。

编辑2:如果我将数据网格移出用户控件,然后直接将其放到选项卡中,它的行为相同。 因此,我认为这与此无关。

编辑3:解决了注释-好像Costura无法嵌入System.Windows.Interactivity。

您必须添加system.windows.interactivity的引用,然后将其用于EventTrigger

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM