禁用 Windows Phone 工具包中的 MenuItem

发布于 2024-12-21 07:16:12 字数 955 浏览 2 评论 0原文

我想禁用 contextMenu 中的一些菜单项,但不是全部。

 <tk:ContextMenuService.ContextMenu>
                            <tk:ContextMenu Name="optionMenu">

                                <tk:MenuItem Header="Move to Favorite" Name="moveToFav" Click="moveToFav_Click" />
                                <tk:MenuItem Header="Copy to Favorite" Name="copyToFav" Click="copyToFav_Click" />
                                <tk:MenuItem Header="Set as Folder Front" Name="setFront" Click="setFront_Click" />
                                <tk:MenuItem Header="Delete" Name="delete" Click="delete_Click" />
                            </tk:ContextMenu>
                        </tk:ContextMenuService.ContextMenu>

例如,我想禁用 moveToFav、copyToFav MenuItem,我尝试

moveToFav.isEnabled = false; copyToFav.isEnable = false;

但它不起作用,因为编译器说 moveToFav 在当前上下文中不存在。

有帮助吗?

I want to disable some menuItems in a contextMenu, but not all of them.

 <tk:ContextMenuService.ContextMenu>
                            <tk:ContextMenu Name="optionMenu">

                                <tk:MenuItem Header="Move to Favorite" Name="moveToFav" Click="moveToFav_Click" />
                                <tk:MenuItem Header="Copy to Favorite" Name="copyToFav" Click="copyToFav_Click" />
                                <tk:MenuItem Header="Set as Folder Front" Name="setFront" Click="setFront_Click" />
                                <tk:MenuItem Header="Delete" Name="delete" Click="delete_Click" />
                            </tk:ContextMenu>
                        </tk:ContextMenuService.ContextMenu>

for example, I want to disable moveToFav, copyToFav MenuItem, I try to

moveToFav.isEnabled = false; copyToFav.isEnable = false;

But It didn't work because the compiler said moveToFav doesn't exist in the current context.

Any Help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煞人兵器 2024-12-28 07:16:12

执行以下操作

<tk:ContextMenuService.ContextMenu>
                            <tk:ContextMenu x:Name="optionMenu" >

                                <tk:MenuItem Header="Move to Favorite" x:Name="moveToFav" Click="moveToFav_Click" Loaded="moveToFav_Loaded" />
                                <tk:MenuItem Header="Copy to Favorite" Name="copyToFav" Click="copyToFav_Click" Loaded="copyToFav_Loaded" />
                                <tk:MenuItem Header="Set as Folder Front" Name="setFront" Click="setFront_Click" Loaded="setFront_Loaded" />
                                <tk:MenuItem Header="Delete" Name="delete" Click="delete_Click" />
                            </tk:ContextMenu>
                        </tk:ContextMenuService.ContextMenu>

好吧,我决定在代码中

private void moveToFav_Loaded(object sender, RoutedEventArgs e)
    {
        if (condition)
            (sender as MenuItem).IsEnabled = false;
    }

    private void copyToFav_Loaded(object sender, RoutedEventArgs e)
    {
        if (condition)
            (sender as MenuItem).IsEnabled = false;
    }

:它并不完美,但它有效

well, I decided to do the following

<tk:ContextMenuService.ContextMenu>
                            <tk:ContextMenu x:Name="optionMenu" >

                                <tk:MenuItem Header="Move to Favorite" x:Name="moveToFav" Click="moveToFav_Click" Loaded="moveToFav_Loaded" />
                                <tk:MenuItem Header="Copy to Favorite" Name="copyToFav" Click="copyToFav_Click" Loaded="copyToFav_Loaded" />
                                <tk:MenuItem Header="Set as Folder Front" Name="setFront" Click="setFront_Click" Loaded="setFront_Loaded" />
                                <tk:MenuItem Header="Delete" Name="delete" Click="delete_Click" />
                            </tk:ContextMenu>
                        </tk:ContextMenuService.ContextMenu>

in the code:

private void moveToFav_Loaded(object sender, RoutedEventArgs e)
    {
        if (condition)
            (sender as MenuItem).IsEnabled = false;
    }

    private void copyToFav_Loaded(object sender, RoutedEventArgs e)
    {
        if (condition)
            (sender as MenuItem).IsEnabled = false;
    }

it's not perfect, but it works

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文