2 回答
TA贡献1780条经验 获得超5个赞
我想说,DataGrid在你的例子中, a 是一个错误的地方ContextMenu。将您的ContextMenu资源放入窗口资源并将其用于DataGridCell.
<Window.Resources>
<ContextMenu x:Key="contMen" HorizontalContentAlignment="Right" FlowDirection="RightToLeft">
<MenuItem Name="addToBlackListMnuBtn" Header="Add to Black List" Click="addToBlackListMnuBtn_Click" FontWeight="Black"/>
<MenuItem Name="addtoReportedListMnuBtn" Header="Add to Reported List" Click="addtoReportedListMnuBtn_Click" FontWeight="Black"/>
</ContextMenu>
</Window.Resources>
<DataGrid.Resources>
<Style TargetType="DataGridCell">
<Setter Property="ContextMenu" Value="{StaticResource contMen}"/>
</Style>
</DataGrid.Resources>
private void addtoReportedListMnuBtn_Click(object sender, RoutedEventArgs e)//add to reported list
{
var en = (((sender as MenuItem).Parent as ContextMenu).PlacementTarget as DataGridCell).DataContext as ObjClass;
if (en != null)
{
ReportSignalsListQ.Data = en; // add to queue for adding
}
else
{
MessageBox.Show("Please select again");
}
}
TA贡献1801条经验 获得超8个赞
当您ItemSource
更新时,SelectedItem
您的信息DataGrid
将被清除。SelectionChanged
因此,您可以向您添加一个事件DataGrid
,并且需要将您分配SelectedItem
给代码隐藏中的局部变量,然后将局部变量添加到第二个DataGrid
。
- 2 回答
- 0 关注
- 170 浏览
添加回答
举报