WPF如何实现DataGrid的右键出现选项菜单的功能

WPF如何实现DataGrid的右键出现选项菜单的功能,第1张

<DataGrid >/////////////////////////////////////////////////// <DataGrid.ContextMenu>

<ContextMenu Name="cmList" StaysOpen="true" Background="Cornsilk">

<ContextMenu.BitmapEffect>

<OuterGlowBitmapEffect />

</ContextMenu.BitmapEffect>

<MenuItem Header="查看XPS文件" Name="cmuView" Click="cmuView_Click">

<MenuItem.Icon>

<Image Width="32" Height="32" Source="/iStarMEScomponent/Images/view.png"/>

</MenuItem.Icon>

</MenuItem>

<Separator/>

<MenuItem Header="删除" Name="cmuDelete" Click="cmuDelete_Click">

<MenuItem.Icon>

<Image Width="32" Height="32" Source="/iStarMEScomponent/Images/delete.ico"/>

</MenuItem.Icon>

</MenuItem>

</ContextMenu>

</DataGrid.ContextMenu>///////////////////////////////////////////这些就是右键的菜单了..其中的事件也可以直接加上去的

<DataGrid.Columns>

<DataGridTextColumn Header="文件编号" Binding="{Binding Path=filecode}" />

<DataGridTextColumn Header="文件名称" Binding="{Binding Path=filename}" />

<DataGridTextColumn Header="文件版本" Binding="{Binding Path=versions}" />

<DataGridTextColumn Header="归属产品" Binding="{Binding Path=partcode}" /> </DataGrid.Columns>

</DataGrid>

public class ResourcesSettingViewModel : SoftGuidanceViewModelBase

2 {

3 #region Contructor

4 public ResourcesSettingViewModel()

5 : this(new ResourcesSettingModel())

6 {

7

8 }

9 public ResourcesSettingViewModel(ResourcesSettingModel resourcesSettingModel)

10 {

11 this.resourcesSettingModel = resourcesSettingModel

12

13 }

14 #endregion

15 #region Variables

16

17 private ResourcesSettingModel resourcesSettingModel

18

19 #endregion

20 #region Properties

21 public ResourcesSettingModel ResourcesSettingModel

22 {

23 get { return this.resourcesSettingModel}

24 }

25 private EverTreeViewItem selectedTreeViewItem

26

27

28 public EverTreeViewItem SelectedTreeViewItem

29 {

30 get { return this.selectedTreeViewItem}

31 set

32 {

33 if (this.selectedTreeViewItem == value)

34 {

35 return

36 }

37 this.selectedTreeViewItem = value

38 this.RaisePropertyChanged(() =>this.SelectedTreeViewItem)

39 }

40 }

41

42

43 #endregion

44 #region Command

45 public ICommand MenuAddCommand

46 {

47 get

48 {

49 return new DelegateCommand(()=>

50

51 {

52 MessageBox.Show("")

53 })

54 }

55 }

56

57

58

59

60

61 #endregion

62

63 //private EverTreeViewItem GetSelectdTreeViewItem()

64 //{

65 //EverTreeViewItem treeViewItem = (EverTreeViewItem)SelectedTreeViewItem

66 //return treeViewItem

67 //}

68 }

<ContextMenu>

<ContextMenu.Items>

<ListBox>

<ListBoxItem Content="fsdfsdf"/>

<ListBoxItem Content="111111111111"/>

</ListBox>

<TextBlock Text="fdsfsdf"/>

<TextBlock Text="fsdfsddddddddddddddddddddddd"/>

</ContextMenu.Items>

</ContextMenu>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11718881.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存