1

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

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;

从运行调试器开始,它显示在更改时调用 getter 以检索InIdle,但点击仍然排队,这导致一个按钮事件一个接一个地触发。

编辑:添加了视觉树以显示一个按钮,没有在ToolBar.

4

0 回答 0