2012-03-29 22 views
1

我正在開發一個使用PRISM和MVVM以及WPF的.NET 4.0應用程序。使用PRISM顯示模態對話框4

我目前有一個區域被細分,其中插入了視圖。當用戶點擊其中一個視圖中的按鈕時,我想要在所有視圖之上顯示一個定製的模式對話框,但仍然位於同一個外殼內。

我查看了StockTrader RI示例及其RegionPopupBehavior的實現。基本上,他們創建了一個依賴屬性,允許他們用特定的定製行爲來定義區域。行爲是負責處理其關聯視圖的呈現的行爲,因此將其顯示爲彈出窗口。

這種方法唯一的缺點是所有其他視圖仍然是活動的,所以彈出窗口不是模態的。我想這可以通過手動禁用shell中所有不需要的區域來解決,但我不確定這是多麼「乾淨」。

我想知道是否有更好更簡單的方法來顯示棱鏡中的模態彈出視圖?

+0

這是WPF,不Silverlight的,對不對? – 2012-03-29 15:44:44

+0

正確,WPF。我編輯了這個問題,謝謝。 :) – 2012-03-29 15:51:02

+1

也許你可以使用像這樣的東西http://stackoverflow.com/questions/8103743/wpf-c-sharp-inputbox/8103869#8103869?我使用MVVM的修改版本來做同樣的事情。 – eandersson 2012-03-29 16:01:47

回答

2

您可能感興趣的自定義PopupUserControl我在我的博客上發佈的行爲就像那樣。

我通常使用這樣的:

<local:PopupPanel 
    Content="{Binding PopupContent}" 
    local:PopupPanel.PopupParent="{Binding ElementName=SomeParentPanel}" 
    local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}"> 

    <local:PopupPanel.Resources> 
     <DataTemplate DataType="{x:Type local:SomeViewModel}"> 
      <local:SomeView /> 
     </DataTemplate> 
     <DataTemplate DataType="{x:Type local:DifferentViewModel}"> 
      <local:DifferentView /> 
     </DataTemplate> 
    </local:PopupPanel.Resources> 

</local:PopupPanel> 

雖然你也可以只寫在彈出窗口中的內容,而不是綁定的內容屬性

<local:PopupPanel 
    local:PopupPanel.PopupParent="{Binding ElementName=SomeParentPanel}" 
    local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}"> 

    <Border BorderBrush="Blue" BorderThickness="2"> 
     <local:MyUserControl /> 
    </Border> 
</local:PopupPanel> 
+0

謝謝!你說得對,ViewModel不應該有任何UI元素。我想最好的解決方案是你所建議的:綁定到一個對象,並有數據模板... – 2012-03-29 19:59:04