我的上下文菜单中的项目未执行。 我的xaml:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:arFirmaKomp.Views"
xmlns:arFirmaKomp="clr-namespace:arFirmaKomp" x:Class="arFirmaKomp.Views.ArKlienciView"
xmlns:helpers="clr-namespace:arFirmaKomp.ViewHelpers"
xmlns:cal="http://www.caliburnproject.org"
mc:Ignorable="d" Height="600" Width="1200" >
<Grid>
<ComboBox x:Name="ArKlienciList" SelectedItem="{Binding Path=WybranyArKlient, Mode=OneWayToSource}" DisplayMemberPath="PodmiotyOdbiorcaNazwaSkrocona" HorizontalAlignment="Left" Margin="128,49,0,0" VerticalAlignment="Top" Width="134" Height="22" />
<DataGrid x:Name="ArKlienciList2" ItemsSource="{Binding Path=ArKlienciICView}" SelectedItem="{Binding SelectedItem}"
cal:Message.Attach="[Event CellEditEnding]=[Action SaveChanges()];[Event MouseDoubleClick] = [Action RowSelect()]"
RowDetailsVisibilityMode="VisibleWhenSelected" Margin="17,80,10,20" EnableRowVirtualization="True" AutoGenerateColumns="False"
Tag="{Binding DataContext, RelativeSource={RelativeSource Self}}" >
<DataGrid.Resources>
<helpers:BindingProxy x:Key="proxy" Data="{Binding}" />
<ContextMenu x:Key="ContextMenu" cal:Action.TargetWithoutContext="{Binding}" IsOpen="{Binding Data.IsContextMenuOpen, Source={StaticResource proxy}}">
<MenuItem Header="Open"
cal:Message.Attach="Open($dataContext)">
</MenuItem>
</ContextMenu>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn x:Name="idColumn" Width="SizeToHeader" Header="Id" Binding="{Binding Id}"/>
<DataGridTextColumn x:Name="nexoKlientNabywcaColumn" Width="SizeToHeader" Header="Nexo Klient Nabywca" Binding="{Binding PodmiotyNabywcaNazwaSkrocona,Mode=OneWay}">
</DataGridTextColumn>
<DataGridTextColumn x:Name="nexoKlientOdbiorcaColumn" Width="SizeToHeader" Header="Nexo Klient Odbiorca" Binding="{Binding PodmiotyOdbiorcaNazwaSkrocona,Mode=OneWay}"/>
<DataGridTextColumn x:Name="nexoKlientOdbiorcaTelefonColumn" Width="SizeToHeader" Header="Nexo Odbiorca Telefon" Binding="{Binding OdbiorcaTelefon,Mode=OneWay}"/>
</DataGrid.Columns>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow" BasedOn="{StaticResource {x:Type DataGridRow}}">
<Setter Property="ContextMenu" Value="{StaticResource ContextMenu}" />
</Style>
</DataGrid.RowStyle>
</DataGrid>
<TextBox HorizontalAlignment="Left" x:Name="FilterString" Height="19" Margin="128,15,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="134"/>
<Label Content="filtr odbiorca" HorizontalAlignment="Left" Height="26" Margin="17,15,0,0" VerticalAlignment="Top" Width="92"/>
</Grid>
我的视图模型-上下文菜单部分:
public void Open(object source)
{
MessageBox.Show((string)source);
}
我的bindingProxy来自Thomas Levesque Blog
我可以看到此上下文菜单,正如我在其他类似文章中所看到的那样,上下文菜单未与我的ViewModel连接,并且我不知道如何连接它。 Contextmenu应该使用选定的行作为参数进行一些操作。