gpt4 book ai didi

windows-phone-7 - 隐藏空的上下文菜单

转载 作者:行者123 更新时间:2023-12-01 11:02:22 26 4
gpt4 key购买 nike

我在 wp7 中有一个上下文菜单

<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="onHoldContextMenu">
<toolkit:MenuItem Header="Delete" Tag="{Binding}" Click="DeleteVisitorNote_Click" Visibility="{Binding DeleteContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<toolkit:MenuItem Header="View" Tag="{Binding}" Visibility="{Binding ViewContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" Click="ViewVisitorContact_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>

我正在更改 View 模型中两个项目的可见性,它工作正常。我的问题是,当我将这两个项目的可见性设置为 false 时,打开上下文菜单时我有一条空白的白线,而且我不知道如何隐藏它...我试过:

<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu x:Name="onHoldContextMenu" Visibility="{Binding ContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}">
<toolkit:MenuItem Header="Delete" Tag="{Binding}" Click="DeleteVisitorNote_Click" Visibility="{Binding DeleteContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<toolkit:MenuItem Header="View" Tag="{Binding}" Visibility="{Binding ViewContextVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" Click="ViewVisitorContact_Click"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>

但在这种情况下,我得到一个 nullreference 异常......

当上下文菜单为空时如何隐藏它?

最佳答案

我在另一个论坛上找到了这个解决方案。

        <ListBox.ItemTemplate> 
<DataTemplate>
<Grid Hold="Grid_Hold">
<toolkit:ContextMenuService.ContextMenu>
... context menu items ...
</toolkit:ContextMenuService.ContextMenu>

... listbox item contents ...

</Grid>
</DataTemplate>
</ListBox.ItemTemplate>

private void Grid_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
ItemViewModel listitem = (sender as FrameworkElement).DataContext as ItemViewModel;
e.Handled = listitem.DisableContextMenu();
}

设置 e.Handled = true 会阻止 ContextMenu 接收 Hold 事件。在您的 View 模型中,您将实现一些返回是否显示 ContextMenu 的属性或方法。

关于windows-phone-7 - 隐藏空的上下文菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9567982/

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