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 關注
- 243 瀏覽
添加回答
舉報