我剛開始看Caliburn Micro。但是,我對使用DevExpress導航欄和MVVM模式做了一些研究。我向開發團隊請教了一個例子。他們說,他們的控制中存在一個錯誤,使其無法正常工作。他們確實給出了一個解決問題的例子。鏈接在這裏: http://www.devexpress.com/Support/Center/p/Q347737.aspx
我看着他們的解決方案,這對我來說太複雜了。希望該補丁即將推出。
基思
UPDATE 我不知道該鏈接沒有工作。下面是該解決方案的更詳細的解釋:
控制的導航欄創建一個用戶:
<UserControl x:Class="NavBarMVVM.View.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/navbar"
xmlns:ext="clr-namespace:NavBarExtensions;assembly=NavBarExtensions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
<Grid>
<dxn:NavBarControl x:Name="navBar">
<dxn:NavBarControl.View>
<dxn:NavigationPaneView/>
</dxn:NavBarControl.View>
<i:Interaction.Behaviors>
<ext:NavBarMVVMAttachedBehavior ItemsSource="{Binding}">
<ext:NavBarMVVMAttachedBehavior.GroupStyle>
<Style TargetType="ext:NavBarGroupWrapper">
<Setter Property="Header" Value="{Binding Caption}"/>
<Setter Property="ItemsSource" Value="{Binding ItemsViewModel}"/>
</Style>
</ext:NavBarMVVMAttachedBehavior.GroupStyle>
<ext:NavBarMVVMAttachedBehavior.ItemStyle>
<Style TargetType="ext:NavBarItemWrapper">
<Setter Property="Content" Value="{Binding Name}"/>
<Setter Property="ImageSource" Value="{Binding PhotoImageSource}"/>
<Setter Property="Command" Value="{Binding ClickItemCommand}"/>
</Style>
</ext:NavBarMVVMAttachedBehavior.ItemStyle>
</ext:NavBarMVVMAttachedBehavior>
</i:Interaction.Behaviors>
</dxn:NavBarControl>
</Grid>
兩個目標類型兩類稱爲*包裝。他們做這樣的綁定: BindingOperations.SetBinding(NavBarGroup,NavBarGroup.ContentProperty,new Binding(「Content」){Source = this});
注意,這個引用是一個名爲NavBarGroup的類。有四個幫手組。 NavBarGroup,NavBarItems,NavBarGroups(NavBarGroup的列表)和NavBarItems(NavBarItem的列表) 這些類由另外四個將數據保存爲靜態成員的等價類填充。正是這些最後階級對我來說是交易中斷者。它似乎越過了過於複雜的界限。 希望有所幫助。 Keith
我不確定我看到您的虛擬機和您的視圖之間的關係。 vm上的屬性應該是'PluginPresenter'而不是'Plugins'? 另外,我們通常認爲在vm中具有控制特定的代碼是一種不好的模式。我對NavBarControl不是很熟悉,你試圖完成的最終結果是什麼? – 2011-03-11 14:38:36
我想要一個基於插件的系統(DLL在一個目錄中)。 DLL的名稱將顯示在列表中供用戶選擇,並且名稱將用於加載DLL(插件)以及在視圖中向用戶顯示的表單 – 2011-03-12 03:33:56