我創建了一個BaseWindowView
和我想在我的所有應用程序的基礎要使用的自定義的框架BaseViewModel
。如何在應用程序中使用框架中的視圖? (WPF MVVM)
在BaseViewModel
我有,例如,其允許我添加按鈕的方法。我可以定義一個Command
,一個ButtonImage
和LabelString
。下面是這個方法的調用示例代碼:
AddButton(OpenAnyTabCommand, "../Images/image.png", "LabelString");
在我BaseWindowView
我有一個RibbonMenue
,所有我在BaseViewModel
定義了RibbonButtons
都顯示:
<ItemsControl x:Name="CButtons" ItemsSource="{Binding Buttons}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel x:Name="ButtonStackPanel" Orientation="Horizontal">
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ribbon:RibbonButton
x:Uid="Button"
LargeImageSource="{Binding Path=ImageString}"
Label="{Binding Path=LabelString}"
Command="{Binding Path=ButtonCommand}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我有這在一個示例項目中,並且工作正常。現在我想將BaseWindowView
和BaseViewModel
外包給一個框架並從那裏使用它。
我的計劃是:在我的每個應用程序中,我想將BaseWindowView
設置爲我的應用程序的MainWindow
。在這個應用程序本身,我只想要一些UserControls
這應該顯示爲我的BaseWindowView
中的選項卡。我在BaseViewModel
定義的按鈕應該調用定義Command
這將打開一個新的標籤,並顯示此Command
背後的ViewModel
。
那麼,什麼是處理我的問題的最好方法是什麼?我知道XAML中沒有「經典繼承」。我可以做一些像在框架視圖中將中的StartUpUri
這樣的定義,還是「稍微有點棘手」?
作爲補充:我發現我可以在App.xaml
像下面的定義DataTemplate
用於TabItems
(其是UserControls
):
<DataTemplate DataType="{x:Type ViewModel:AnyViewModel}">
<view:TabItemAny/>
</DataTemplate>
@Sheridan:這裏是關於BaseWindowView
的問題。
的問題不是很清楚:這是什麼問題?喲意識到沒有XAML繼承這樣的東西? –
是的,我知道沒有「經典繼承」。我的問題是我如何做一些像視圖的繼承。我想在我的應用程序中顯示我的'Framework-View'作爲MainWindow,並且只需添加一些用於在此窗口中打開Tabs的UserControls。 – Tobias
@Sheridan,這是問題 – Tobias