WPF:通过将鼠标拖到它们上来切换多个按钮

时间:2013-02-08 16:41:24

标签: wpf mouseover togglebutton

是否可以通过将鼠标拖过它们来切换多个ToggleButton的状态(按住鼠标左键)?

2 个答案:

答案 0 :(得分:1)

框中没有任何内容可以支持此功能,但您应该能够订阅MouseMove并在按下按钮时切换状态。

答案 1 :(得分:0)

<ToggleButton Content="ToggleButton" MouseEnter="ToggleButtonMouseEnter" Width="80" HorizontalAlignment="Left"/>

private void ToggleButtonMouseEnter(object sender, MouseEventArgs e)
{
     System.Windows.Controls.Primitives.ToggleButton tb = (System.Windows.Controls.Primitives.ToggleButton)sender;
     if(e.LeftButton == MouseButtonState.Pressed) tb.IsChecked = !tb.IsChecked;
}