2012-05-23 23 views
0

當你點擊它時,我有一個帶有事件處理程序的自定義控件。一切正常,事件被解僱。Wpf自定義用戶控件mouseleftButtonDown捕獲區域

AddHandler (cu.MouseLeftButtonDown), AddressOf Me.DoSomething 

當控制調整大小,以顯示它擴展了一些額外的信息。當用戶偏好一個按鈕時,它也會崩潰。這工作正常。但是現在,當我點擊擴展區域以前的位置時,它仍然會在該控件上觸發鼠標左鍵。我試圖在擴展的元素上將IsHitTestVisible設置爲false,但它沒有工作。下面是一些XAML ...當我使用此代碼

overView.Visibility = Windows.Visibility.Visible 

<UserControl x:Class="MyCustomControl"> 
    <StackPanel> 
     <Grid> 
      'Stuff thats always visible 
     </Grid> 
    <Border IsHitTestVisible="False" Grid.Row="1" HorizontalAlignment="left" BorderThickness="1" VerticalAlignment="top" x:Name="overView" Background="#EEEEEE" Visibility="Hidden" Margin="-325,-95,0,0" Width="auto" Height="auto" Padding="5,5,5,5" BorderBrush="#999999" CornerRadius="3,3,3,3"> 
     <Border IsHitTestVisible="False" x:Name="myBorder" Margin="1" Width="300" Height="225" BorderThickness="1" BorderBrush="#999999" Background="#DDDDDD" CornerRadius="3,3,3,3" HorizontalAlignment="Left" VerticalAlignment="Top"> 
      <Rectangle IsHitTestVisible="False" x:Name="rtgOverView"> 
      </Rectangle> 
     </Border> 
    </Border> 
    </StackPanel> 
</UserControl> 

總覽變得可見,隱藏,當我用這個

OverView.Visibility = Windows.Visibility.Collapsed 

我填充矩形用visualbrush。當控件加載時會發生這種情況。

rtgOverView.Fill = visual 

概述變得定位在後面的代碼是這樣

If x > 350 Then 
     overView.HorizontalAlignment = Windows.HorizontalAlignment.Left 
     overView.Margin = New Thickness(-325, -95, 0, 0) 
    Else 
     overView.HorizontalAlignment = Windows.HorizontalAlignment.Right 
     overView.Margin = New Thickness(0, -95, -300, 0) 
    End If 

我不能用我的身邊另一customcontrol元素,因爲我還對所有不同類型的控件使用的MouseLeftButtonDown。 我無法弄清楚cu.MouseLeftButtonDown事件的邊界如何解決這個問題。

回答

1

隨着堆疊面板的大小發生了一些奇怪的事情。這就像自動屬性不會縮小它的大小。我設法解決這個問題。當鼠標進入我把:

layoutroot.ClipToBounds = False 

這使我可以顯示控制之外的內容。 當鼠標離開我用:

layoutroot.ClipToBounds = True 

的剪輯約束的某種方式迫使StackPanel的大小更小。