2011-12-01 75 views
1

我想了解Caliburn.Micro附帶的HelloScreens樣本。 ShellView.xaml包括在底部的ContentControl。有人可以解釋這個元素的重要性嗎?我試圖評論它沒有看到任何區別。Caliburn.Micro,HelloScreens-sample

<UserControl x:Class="Caliburn.Micro.HelloScreens.Shell.ShellView" 
      xmlns:...> 
    <Grid> 
    <local:TiledBackground SourceUri="/Resources/Images/backgroundtexture.png" /> 
     <Image Source="/Resources/Images/backgroundshadow.png" 
       Stretch="Fill" /> 

     <ct:DockPanel> 
      <.../> 
     </ct:DockPanel> 

     <!-- Whats this one for? --/> 
     <ContentControl x:Name="Dialogs" 
         VerticalContentAlignment="Stretch" 
         HorizontalContentAlignment="Stretch"/> 
    </Grid> 

</UserControl> 

它綁定到的ViewModels Dialogs - 屬性,這是一個IConductActiveItem定製實現,但它是什麼用的?

回答

5

無論何時您的ContentControl與視圖模型屬性的名稱相同,Caliburn.Micro都會爲該視圖模型找到相應的視圖,將視圖注入ContentControl,並將視圖模型綁定到視圖。

在這種情況下,Dialogs屬性是如你所說的IDialogManager類型,其解析爲DialogConductorViewModel(導體類型)。所以DialogConductorView被注入到內容控件中。

此視圖顯示應用程序中的對話框,如果您查看視圖,它也有一個ContentControl,它顯示當前的ActiveItem。這是Caliburn.Micro導體的典型特徵。

<Controls:CustomTransitionControl x:Name="ActiveItem" Margin="8" /> 

注意,DialogConductorViewShellView始終顯示在應用程序的內容,但DialogConductorViewGrid纔可見如果ActiveItem不爲空。

<Grid Visibility="{Binding ActiveItem, Mode=TwoWay, 
Converter={StaticResource nullToCollapsed}}" 
+0

啊哈!我錯過了那一個。我還沒有詳細看過對話框,但假設他們住在每個工作區內。所以當我刪除內容控件,並且工作區之間的切換仍然有效時,我開始相信對話管理員根本沒有任務... 非常感謝! – Vegar

+0

所以這裏是問題..應該使用窗口還是這個方法? – GorillaApe

+0

任何一種技術都是有效的,這取決於你希望你的對話框是一個模態窗口,還是內容覆蓋當前窗口。 – devdigital