简体   繁体   中英

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

I may be overlooking something obvious here, but I can't see it for the life of me right now.

I've got an interaction on a user control (data grid) which has an item source bound to an ICollectionView, but the DataContext is inherited from the parent window:

<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>

The DataContext is inherited from the parent window, which has a tabbed view:

<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>

For now, the OnNotifyPeg command just opens a window (via a service, but also a messagebox to debug for now)

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

}

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

Whilst running from within Visual Studio, it works fine - the uc fires off the Command.

But when I run from the Debug or Release folders, nothing happens. No error, no window, nothing - as far as I can tell, it's not bound in the built application?

Edit: Also to add, the columns still load their data fine from the ItemSource (Which uses the data context).

Edit 2: If I move the data grid out of a user control and put it into the tab directly, it's doing the same behaviour. So I don't think it's related to that.

Edit 3: Solved in comments - looks like Costura fails at embedding System.Windows.Interactivity.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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