2012-02-07 17 views
0

而不是在我的MainWindow的中心託管我的模態對話框,我想將它託管在我的MainWindow內的一個ContentControls中。希望有人能告訴我如何去做這件事。謝謝。在ContentControl中承載一個模態對話框

+2

你是說「模態對話框」是什麼意思?舉個例子。 – Seekeer 2012-02-07 08:12:13

回答

0

我有一個自定義UserControl內置完成此行爲。與代碼的文章中找到here,它可以這樣使用:

<local:PopupPanel 
    Content="{Binding PopupContent}" 
    local:PopupPanel.PopupParent="{Binding ElementName=PopupParentPanel}" 
    local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}" /> 
+0

非常感謝,Rachel ...... :) – bbdaffy 2012-02-08 02:01:26

1

我有一個自定義FrameworkElement,讓您在顯示主要內容模式的內容github一個例子。

控制可以像這樣使用:

<c:ModalContentPresenter IsModal="{Binding DialogIsVisible}"> 
    <TabControl Margin="5"> 
      <Button Margin="55" 
        Padding="10" 
        Command="{Binding ShowModalContentCommand}"> 
       This is the primary Content 
      </Button> 
     </TabItem> 
    </TabControl> 

    <c:ModalContentPresenter.ModalContent> 
     <Button Margin="75" 
       Padding="50" 
       Command="{Binding HideModalContentCommand}"> 
      This is the modal content 
     </Button> 
    </c:ModalContentPresenter.ModalContent> 

</c:ModalContentPresenter> 

特點:

  • 顯示任意內容。
  • 在顯示模態內容時不禁用主內容。
  • 在顯示模態內容時,禁止鼠標和鍵盤訪問主內容。
  • 只對它所覆蓋的內容有效,而不是整個應用程序。
  • 可通過綁定到IsModal屬性以MVVM友好的方式使用。