将IsHitTestVisible设置为false后,鼠标点击仍在排队

时间:2013-06-10 20:50:17

标签: c# wpf mouseclick-event

我有一个窗口,IsHitTestVisible绑定到Singleton中的属性,但每当属性更改时,按钮上的点击仍然排队并处理。我该如何阻止这种情况发生?

XAML绑定:

 <Window x:Class="myLibrary.myWindow"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:my="clr-namespace:System;assembly=mscorlib"
         Loaded="Window_Loaded" MinWidth="500" MinHeight="500"
         IsHitTestVisible="{Binding Source={x:Static Singleton:Variables.Instance}, 
             Path=InIdle, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
         Name="Window">
 <DockPanel Name="dockPanel1" Background="Transparent" LastChildFill="True" >
 <DockPanel DockPanel.Dock="Top">
      <ToolBarTray HorizontalAlignment="Stretch" Name="MenuBar" VerticalAlignment="Top" Height="42" DockPanel.Dock="Left">
           <ToolBar Name="ViewToolbar"  HorizontalAlignment="Left">
                <Button  Click="ViewButtonCommand_Executed" ToolTip="myViewTooltip">
                     <Image Source="{StaticResource myViewButtonIcon}"/>
                </Button>
           </ToolBar>
      </ToolBarTray>
 </DockPanel>
 </Window>

属性:

 private bool _InIdle = true;
 /// <summary>
 /// Tracks whether an action is being processed
 /// </summary>
 public bool InIdle {
      get {
      return _InIdle;
      }
      set {
      if(value != _InIdle) {
           if(value) {
           Mouse.OverrideCursor = Cursors.Arrow;
           }
           else {
           Mouse.OverrideCursor = Cursors.Wait;
           }
           _InIdle = value;
           OnPropertyChanged("InIdle");
      }
      }
 }

然后我通过调用:

来使用setter / getter
 Variables.Instance.InIdle = false;
 // Do stuff
 Variables.Instance.InIdle = true;

从运行调试器开始,它会显示在InIdle发生更改时调用的getter被调用,但点击仍然排队,导致一个按钮事件在另一个按钮事件之后触发。

编辑:添加了可视树以显示按钮,未添加ToolBar中的所有按钮。

0 个答案:

没有答案