我正在尝试创建一个行为如此的UserControl:
这是我的尝试:
<UserControl x:Class="NetBoard.RadialButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:NetBoard"
xmlns:radial="clr-namespace:RadialMenu.Controls;assembly=RadialMenu"
mc:Ignorable="d" >
<Grid>
<Button Name="Button"
PreviewMouseDown="Button_MouseDown"
PreviewMouseUp="Button_MouseUp" />
<radial:RadialMenu Name="RadialMenu" />
</Grid>
</UserControl>
public partial class RadialButton : UserControl
{
public RadialButton()
{
InitializeComponent();
// Test menu items
for (int i = 0; i < 3; i++)
{
RadialMenu.Content.Add(new RadialMenuItem { Content = i });
}
foreach (RadialMenuItem item in RadialMenu.Content)
{
item.PreviewMouseLeftButtonUp += Slice_MouseUp;
}
}
private void Button_MouseDown(object sender, MouseButtonEventArgs e)
{
RadialMenu.IsOpen = true;
}
private void Button_MouseUp(object sender, MouseButtonEventArgs e)
{
RadialMenu.IsOpen = false;
}
private void Slice_MouseUp(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("It worked!");
}
径向菜单弹出正常,但是RadialMenuItems上的PreviewMouseLeftButtonUp事件不会触发。菜单项甚至不会像他们被嘲笑一样(它们会改变颜色)。
关于如何实现这一目标的任何想法?
答案 0 :(得分:0)
我实际上使用Label而不是按钮来实现此功能。