我在一个自定义框架中创建了 aBaseWindowView和 a BaseViewModel,我想在我的所有应用程序中将其用作基础。
例如,在BaseViewModel我有一个允许我添加按钮的方法。我可以定义 a Command、 aButtonImage和 a LabelString。以下是调用此方法的示例代码:
AddButton(OpenAnyTabCommand, "../Images/image.png", "LabelString");
在我的BaseWindowView我有一个我在RibbonMenue其中RibbonButtons定义的所有内容BaseViewModel都显示的地方:
<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>
我在一个示例项目中有这个,它工作正常。现在我想将BaseWindowViewand the外包BaseViewModel给一个框架并从那里使用它。
我的计划是:在我的每个应用程序中,我想将 设置BaseWindowView为MainWindow我的应用程序。在这个应用程序本身中,我只想有一些UserControls应该在我的BaseWindowView. 我在 中定义的按钮BaseViewModel应该调用 defined Command,它会打开一个新选项卡并显示ViewModelthis 后面Command。
那么处理我的问题的最佳方法是什么?我知道 XAML 中没有“经典继承”。我可以做一些像在框架视图中定义的事情StartUpUri还是App.xaml“有点”棘手?
作为补充:我发现我可以定义DataTemplatefor the TabItems(which are UserControls),App.xaml如下所示:
<DataTemplate DataType="{x:Type ViewModel:AnyViewModel}">
<view:TabItemAny/>
</DataTemplate>
@Sheridan:这是关于BaseWindowView.