I'm trying to create a somewhat complex menu item that would allow a user to create a new class. The problem into which I am running is that when I click on a numeric up-down ( from the xceed toolkit ) that the menu item closes, even with the property StaysOpenOnClick
set to true.
我正在尝试创建一个有点复杂的菜单项,允许用户创建一个新类。我正在运行的问题是当我点击数字上下(从xceed工具包)菜单项关闭时,即使将属性StaysOpenOnClick设置为true。
Users will not like that.
用户不会喜欢这样。
To reproduce, create a WPF project and add the Extended WPF Toolkit through NuGet, then drop the following code into your mainwindow class :
要重现,创建一个WPF项目并通过NuGet添加Extended WPF Toolkit,然后将以下代码放入mainwindow类:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WhyDoesMyMenuItemCloseWhenClicked"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
x:Class="WhyDoesMyMenuItemCloseWhenClicked.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="21"/>
<RowDefinition />
</Grid.RowDefinitions>
<Menu FontWeight="Bold">
<MenuItem Header="_File">
<MenuItem StaysOpenOnClick="True">
<Grid Height="50" Width="50">
<xctk:IntegerUpDown/>
</Grid>
</MenuItem>
</MenuItem>
</Menu>
</Grid>
</Window>
When I click the text field of the integer up-down, the menu closes.
当我单击上下整数的文本字段时,菜单将关闭。
Why does that keep happening? How can I make it NOT happen?
为什么会一直这样?怎么能让它不发生?
2 个解决方案
#1
1
I have figured out a solution. It is sort of a terribly hacky workaround, but it does the job quite well :
我找到了解决方案。这是一种非常糟糕的解决方法,但它做得很好:
The change is that you create a MenuItem
within the MenuItem
. Then you define your control within the sub MenuItem
's MenuItem.Header
property, and set that MenuItem
's StaysOpenOnClick
property to true.
更改是您在MenuItem中创建MenuItem。然后在子MenuItem的MenuItem.Header属性中定义控件,并将MenuItem的StaysOpenOnClick属性设置为true。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WhyDoesMyMenuItemCloseWhenClicked"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
x:Class="WhyDoesMyMenuItemCloseWhenClicked.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="21"/>
<RowDefinition />
</Grid.RowDefinitions>
<Menu FontWeight="Bold">
<MenuItem Header="_File" StaysOpenOnClick="True">
<MenuItem Header="_StaysOpenOnClick">
<MenuItem StaysOpenOnClick="True">
<MenuItem.Header>
<xctk:IntegerUpDown/>
</MenuItem.Header>
</MenuItem>
</MenuItem>
</MenuItem>
</Menu>
</Grid>
</Window>
#2
-1
you can make use of StaysOpenOnClick
Property to achieve this
您可以使用StaysOpenOnClick属性来实现此目的
#1
1
I have figured out a solution. It is sort of a terribly hacky workaround, but it does the job quite well :
我找到了解决方案。这是一种非常糟糕的解决方法,但它做得很好:
The change is that you create a MenuItem
within the MenuItem
. Then you define your control within the sub MenuItem
's MenuItem.Header
property, and set that MenuItem
's StaysOpenOnClick
property to true.
更改是您在MenuItem中创建MenuItem。然后在子MenuItem的MenuItem.Header属性中定义控件,并将MenuItem的StaysOpenOnClick属性设置为true。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WhyDoesMyMenuItemCloseWhenClicked"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
x:Class="WhyDoesMyMenuItemCloseWhenClicked.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="21"/>
<RowDefinition />
</Grid.RowDefinitions>
<Menu FontWeight="Bold">
<MenuItem Header="_File" StaysOpenOnClick="True">
<MenuItem Header="_StaysOpenOnClick">
<MenuItem StaysOpenOnClick="True">
<MenuItem.Header>
<xctk:IntegerUpDown/>
</MenuItem.Header>
</MenuItem>
</MenuItem>
</MenuItem>
</Menu>
</Grid>
</Window>
#2
-1
you can make use of StaysOpenOnClick
Property to achieve this
您可以使用StaysOpenOnClick属性来实现此目的