English 中文(简体)
WPF: Menu 只限值一次的项目
原标题:WPF: Menu Items only bind command parameters once

我注意到,在使用与指挥的男子时,他们有两倍时间,但不是很活跃的,就是这样做的。 我正在从一组颜色中制造一个菜单,我把它用在数据网中一栏。 第一次提升菜单(背景菜单)时,有约束力的指挥参数发生,并且与背景菜单一栏相约束。 然而,在接下来的一段时期内,它似乎 w了菜.,并有意将指挥参数合并起来。 因此,我只能把颜色放在背景菜单上。

过去,我一直围绕着这一局势,使菜单完全活跃,在菜单关闭时销毁收集工作,并迫使它在今后开工时进行重建,即象这个黑板一样。 谁会走更好的道路?

    <MenuItem
       Header="Colour"
       ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:ResultEditorGrid}}, Path=ColumnColourCollection}"
       ItemTemplate="{StaticResource colourHeader}" >
       <MenuItem.Icon>
          <Image
             Source="{StaticResource ColumnShowIcon16}" />
       </MenuItem.Icon>
       <MenuItem.ItemContainerStyle>
          <Style
             TargetType="MenuItem"
             BasedOn="{StaticResource systemMenuItemStyle}">
             <!--Warning dont change the order of the following two setters
                                otherwise the command parameter gets set after the command fires,
                                not mush use eh?-->
             <Setter
                Property="CommandParameter">
                <Setter.Value>
                   <MultiBinding>
                      <MultiBinding.Converter>
                         <local:ColumnAndColourMultiConverter/>
                      </MultiBinding.Converter>
                      <Binding RelativeSource="{RelativeSource AncestorType={x:Type DataGridColumnHeader}}" Path="Column"/>
                      <Binding Path="."/>
                   </MultiBinding>
                </Setter.Value>
             </Setter>
             <Setter
                Property="Command"
                Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:ResultEditorGrid}}, Path=ColourColumnCommand}" />
          </Style>
       </MenuItem.ItemContainerStyle>
    </MenuItem>
最佳回答

问题是,背景标准是。 a. 自己的直观树根: 我读到的有些地方是,它掌握了母子的数据,但只是在装货上过一次,这样,如果父母的数据对菜单进行改动,则单项没有改变。 (不幸的是,我找不到与这项权利的联系)

我以前曾遇到过这一问题,我曾经使用过Josh Smith s虚拟处。 这篇文章比较技术性,但有助于我真正了解与这种视觉树苗不相干的情况。

基本上,你创建了这一桥梁,与数据基相连接。 这座桥梁是作为固定资源建立的,使你能够从地表上对它进行约束,即使它不在视觉树上。

添加这段文字如下:

<Window.Resources>
   <!-- This is the "root node" in the virtual branch
   attached to the logical tree. It has its
   DataContext set by the Binding applied to the
   Window s DataContext property. -->
   <FrameworkElement x:Key="DataContextBridge" />
</Window.Resources>

<Window.DataContext>
   <!-- This Binding sets the DataContext on the "root node"
   of the virtual logical tree branch.  This Binding
   must be applied to the DataContext of the element
   which is actually assigned the data context value. -->
   <Binding
    Mode="OneWayToSource"
    Path="DataContext"
    Source="{StaticResource DataContextBridge}"
   />
</Window.DataContext>

这是我所说的桥梁。 它将数据内容和内容推向桥梁数据内容,即(如我前面所述)静态资源。

然后,你简单地看一下数据内容:

 DataContext="{Binding
               Source={StaticResource DataContextBridge},
               Path=DataContext}"

现在,放弃一切相对途径,在菜单项目内使用定期约束,你应被罚款。 数据内容将一如既往地更新。

Just one note:

很明显,在数据内容中,你一定要掌握一些财产,才能发现哪些财产需要使用,但我相信你能够表明这一点。 这一解决办法只是处理环境方面的最新情况

问题回答

暂无回答




相关问题
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 ...

热门标签