繁体   English   中英

根据列表视图项禁用/启用上下文菜单项

[英]Disable/Enable context menu item depending on listview item

我有一个带有ListViewUserControl 另外,我有一个类listViewItems.cs ,其中DisplayMemberBinding到listViewGridView

每个ListView-Item都有一个上下文菜单。 现在我正在尝试启用/禁用context-menu-items,具体取决于ListViewItems类中的值是否为null

我已经尝试将IsEnabled属性绑定到类ListViewItems.cs中的布尔值ShowResItemEn ,但它不起作用。

DataOutput.xaml

<ListView.Resources>
    <ContextMenu x:Name="cmListView" x:Key="ItemContextMenu" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}"> 
        <MenuItem x:Name="itmRes"
                    Header="Reservierungen anzeigen"
                    IsEnabled="{Binding PlacementTarget.SelectedItem.ShowResItemEn, RelativeSource={RelativeSource FindAncestor,AncestorType=ContextMenu}}"
                    Command="{Binding ShowResItemCmd}"
                    CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}" >
        </MenuItem>
    </ContextMenu>
</ListView.Resources>

class ListViewItems.cs

public Boolean ShowResItemEn
{
   get
   {
       return (auftrNr[0] == null) ? false : true; 
   }
}

好吧现在有效。 我已经设置了AncestorType错误

IsEnabled="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}},Path=SelectedItem.ShowBesItemEn}"       

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM