我有一個正確使用Caliburn.Micro的View/ViewModel對。如何使用Caliburn.Micro而不是這些DataTriggers應用convention-over-configuration?
視圖裏面,有一個ContentControl中,我想爲ContentControl中不同的模板,其內容被綁定到相同的視圖模型,並根據在視圖模型給定的枚舉屬性的值:
<ContentControl Content="{Binding}">
<ContentControl.Resources>
<DataTemplate x:Key="TurnedOffView">
<local:TurnedOffView/>
</DataTemplate>
<DataTemplate x:Key="DeviceReadyView">
<local:DeviceReadyView/>
</DataTemplate>
</ContentControl.Resources>
<ContentControl.Style>
<Style TargetType="ContentControl">
<Setter Property="ContentTemplate" Value="{StaticResource TurnedOffView}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="{x:Static local:DeviceStates.Ready}">
<Setter Property="ContentTemplate" Value="{StaticResource DeviceReadyView}"/>
</DataTrigger>
<!-- More DataTriggers here, one for each state -->
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
我知道Caliburn.Micro可以使用cal:View.Model
和cal:View.Context
,以便可以將多個視圖綁定到每個ViewModel,但我無法弄清楚如何使用它來避免所有這些冗長。
所以,問題是:
我應該如何使用
View.Model
和View.Context
(並重新命名我的看法)在這種情況下采取Caliburn.Micro約定優於配置方法的優勢在哪裏?
我一直很困惑:在'Project.Views.MainView.Main.TurnedOff'中,名稱空間何處結束,類名是從哪裏開始的?對於'TurnedOff'視圖,我的完全合格的類名應該是什麼? – heltonbiker 2014-11-03 21:32:42
@mvermef謝謝,我想我現在明白了,明天再試一試。同時,如果您想將此作爲答案發布,我會很樂意接受它(如果它有效)(此外,此信息缺失或非常隱蔽,因爲我沒有在文檔中找到它)。 – heltonbiker 2014-11-03 23:19:13