我正在使用框架Catel,并且我有一个ViewControl,它由一个项目源提供的TabControl。 TabContent是用Datatemplate完成的,里面有命令。其中一个命令需要打开一个显示TabContent内容的新窗口。从模型创建一个ViewModel
我想要做什么?我将命令放在模型中打开新窗口(因为从DataTemplate处于模型上下文中)。命令被正确调用,但是,我无法引用我的模型中的ViewModel对象。
我会在这里写一个我的代码的简短版本,以更好地展示问题。
我的看法是:
...
<TabControl Grid.Column="2" ItemsSource="{Binding Plots}" >
...
<views:TabContent.Template>
<DataTemplate>
<Grid>
...
<DockPanel Grid.Column="0">
<ToolBarTray DockPanel.Dock="Left" Orientation="Vertical">
<ToolBar>
<Button Command="{Binding ShowAnotherWindow}">
<Image Source="{StaticResource GalleryPropertyImage}" />
</Button>
</ToolBar>
</ToolBarTray>
</DockPanel>
...
</Grid>
</DataTemplate>
</views:TabContent.Template>
</TabControl>
...
而且我的模型里面我有一个执行命令ShowAnotherWindow
,但我不能这样做:
CompletePlotViewModel viewModel = new CompletePlotViewModel(this);
你推荐什么我做什么?
谢谢吉尔特。工作!这是一个非常准确的答案。再次感谢。 – 2014-09-12 16:26:43