2012-04-29 26 views
0

我創建一個WPF/XAML應用程序DragMove()和MouseDragElementBehaviour不能在同一個窗口中工作?

WindowStyle =「無」

因爲這樣我不必使用

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) 
    { 
     base.OnMouseLeftButtonDown(e); 

     // Begin dragging the window 
     this.DragMove(); 

爲了讓這個窗口可以左右拖動所以屏幕。不過我也想在窗口內使圖像拖能,我準備用

<Image HorizontalAlignment="Right" Height="65" Width="203" Margin="0,278.271,14.434,82.5" Source="Images/Implementation1.png" Stretch="Fill"> 
     <i:Interaction.Behaviors> 
      <ei:MouseDragElementBehavior ConstrainToParentBounds="True"/> 
     </i:Interaction.Behaviors> 
    </Image> 

問題做的是,我不能讓他們既可以在同一窗口中工作,因爲他們只會如果函數其他被關閉。任何幫助將不勝感激。

回答

1

您的OnMouseLeftButtonDown是在整個窗口中定義的,因此會干擾MouseDragElementBehavior的觸發器。

添加Border到你的窗口,給它一個BackgroundTransparent是確定的,只是不離開它沒有背景),並聽取他們對邊境MouseLeftButtonDown事件。在事件處理程序中執行DragMove()

您可以將邊框作爲窗口的標題,也可以放在內容後面。

相關問題