English 中文(简体)
男用物品WPF的开销
原标题:Switch between menu items WPF?
  • 时间:2012-01-13 15:06:33
  •  标签:
  • wpf

我有一份WPF申请。 我对这一应用有不同的用户,每个用户与这些用户有不同程度的联系。 拥有较高水平的护卫人员可以接触一些菜单。

是否有办法在菜单项目之间转用? 是否把单个菜单项目集中起来,能够有效地做到这一点? 是否有其他办法这样做?

最佳回答

You could achieve this using bindings and converters. Basically if you have a property on the DataContext of the menu (which will be inherited by the menu items) that specifies the level of permissions; then you could bind that to the visibility of the menu items.

Obviously, because the permissions would not be implicitly convertible to the Visibility enum, you would have to create an implementation of the IValueConverter interface, which would be specific to converting permissions to visibilities, and vice versa, based on the current permissions level. This would also require the converter having some concept of the current permissions level, so either you would want to give it access to some static property (which I would not advise), or you would need to gain hold of the converter instance (making sure you only use one instance) and pass the current permissions level to it.

问题回答

这样做有几种不同的方式。 集中可见度是一种方式,但如果你想要他人阅读你的法典,我建议采用某种设计模式。

我建议采用多国机器或多国公司模式。 这将意味着你们需要为不同的用户提出不同的看法。

至于像菜单项目这样的简单东西,你可以将贵方倡议的这一部分保存到用户控制中,而在这种用户控制中,不同用户的XAML有不同。 然后,在法典中,根据用户的标记,展示正确的XAML(概览)。

是的,<代码>Visibility property work for MenuItem。 如果你将以下代码贴在Kaxaml,你就会发现Edit menu是隐蔽的,因此也是工具与项目2。

<Menu>
  <MenuItem Header="_File"/>
  <MenuItem Header="_Edit" Visibility="Collapsed"/>
  <MenuItem Header="_Tools">
    <MenuItem Header="Item 1"/>
    <MenuItem Header="Item 2" Visibility="Collapsed"/>
    <MenuItem Header="Item 3"/>
  </MenuItem>
</Menu>

您也可从方案的角度修改<代码>无障碍,或将其并入你的视像仪上的财产。





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签