gpt4 book ai didi

c# - WPF 数据网格行上下文菜单 - 禁用菜单项

转载 作者:太空狗 更新时间:2023-10-29 23:30:57 26 4
gpt4 key购买 nike

<分区>

您好,我是初级程序员,是 WPF 的新手,有一个简单的问题,但我花了很长时间搜索它,但无法弄清楚,所以我希望你们能帮助我。我只想在我的 Datagrid 的上下文菜单中禁用菜单项。例如:如果在 Datagrid 中选择了多行,则禁用上下文菜单项“属性”

<DataGrid.Resources>
<ContextMenu x:Key="DataRowContextMenu">
<MenuItem x:Name="RowContMenuProp" Header="Properties">
<MenuItem.Icon>
<Image Source="Resources/proporties.ico" Height="16" Width="16" />
</MenuItem.Icon>
</MenuItem>
<Separator Margin="0" />
<MenuItem Header="Copy" Command="Copy" >
<MenuItem.Icon>
<Image Source="Resources/copy.ico" Height="16" Width="16" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Remove from list" Click="MenuItem_Click_1" >
<MenuItem.Icon>
<Image Source="Resources/cut.png" Height="16" Width="16" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Remove from project" Click="MenuItem_Click_2" >
<MenuItem.Icon>
<Image Source="Resources/remove.ico" Height="16" Width="16" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</DataGrid.Resources>

<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="ContextMenu" Value="{StaticResource DataRowContextMenu}" />
<Setter Property="BorderThickness" Value="0"/>
</Style>
</DataGrid.RowStyle>

-- 禁用上下文菜单项

Private Sub datagrid1_MouseUp(sender As Object, e As MouseButtonEventArgs)
If datagrid1.SelectedItems.Count > 1 Then

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com