在WPF中,应MVVM ViewModel的参与打开一个窗口,如关于窗口? [英] In WPF,MVVM should ViewModel be involved in opening a window, e.g. About-window?
问题描述
我有一个标准的WPF TreeView和已绑定的物品,查看模型类。
我现在要处理的行为,当项目是双击(打开文档visual-工作室的风格)。
我可以得到事件处理程序在控制住房火树视图(如图所示XAML),但我怎么绑定到具体行为上的观点模型类 - 如: ProjectViewModel
优选结合到ICommand的-实施者,因为这是在别处使用...
为任何由于注释
安德斯,丹麦
<树视图的ItemsSource = {结合项目}MouseDoubleClick =TreeView_MouseDoubleClick>
< TreeView.ItemContainerStyle>
< - !
这种风格结合一个树型视图到TreeViewItemViewModel。
- >
<风格的TargetType ={X:类型的TreeViewItem}>
< setter属性=IsExpandedVALUE ={结合IsExpanded,模式=双向}/>
< setter属性=IsSelectedVALUE ={结合IsSelected,模式=双向}/>
< setter属性=粗细VALUE =正常/>
< Style.Triggers>
<触发属性=IsSelectedVALUE =真>
< setter属性=粗细VALUE =大胆/>
< /触发>
< /Style.Triggers>
< /样式和GT;
< /TreeView.ItemContainerStyle>
< TreeView.Resources>
< HierarchicalDataTemplate数据类型={X:类型实现:ProjectViewModel}的ItemsSource ={结合儿童}>
< StackPanel的方向=横向>
<图像宽度=16高度=16保证金=3,0来源=Images\Region.png/>
< TextBlock的文本={结合显示名称}/>
< / StackPanel的>
< / HierarchicalDataTemplate>
< HierarchicalDataTemplate数据类型={X:类型实现:PumpViewModel}的ItemsSource ={结合儿童}>
< StackPanel的方向=横向>
<图像宽度=16高度=16保证金=3,0来源=Images\State.png/>
< TextBlock的文本={绑定名称}/>
< / StackPanel的>
< / HierarchicalDataTemplate>
<数据类型的DataTemplate ={X:类型实现:PumpDesignViewModel}>
< StackPanel的方向=横向>
<图像宽度=16高度=16保证金=3,0来源=Images\City.png/>
< TextBlock的文本={绑定名称}/>
< / StackPanel的>
< / DataTemplate中>
< /TreeView.Resources>
< / TreeView的>
要在标题-问题:是的。主视图的VM应该显示AboutBox的。
但该消息的身体似乎有所不同,也许你可以在上面一点点扩大?
I have a standard WPF treeview and have bound items to view model classes.
I now wish to handle behaviour when items are double-clicked (opening documents visual-studio-style).
I can get event-handler to fire in the control housing the treeview (xaml shown), but how do I bind to specific behaviour on the view model classes - e.g. ProjectViewModel?
Preferable bound to ICommand-implementer, as this is used elsewhere...
Thanks for any comments,
Anders, Denmark
<TreeView ItemsSource="{Binding Projects}" MouseDoubleClick="TreeView_MouseDoubleClick">
<TreeView.ItemContainerStyle>
<!--
This Style binds a TreeViewItem to a TreeViewItemViewModel.
-->
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type Implementations:ProjectViewModel}" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin="3,0" Source="Images\Region.png" />
<TextBlock Text="{Binding DisplayName}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type Implementations:PumpViewModel}" ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin="3,0" Source="Images\State.png" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type Implementations:PumpDesignViewModel}">
<StackPanel Orientation="Horizontal">
<Image Width="16" Height="16" Margin="3,0" Source="Images\City.png" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</TreeView.Resources>
</TreeView>
To the Title-question: Yes. The VM of the Main View should show the AboutBox.
But the body of the message seems different, maybe you can expand on it a little?
这篇关于在WPF中,应MVVM ViewModel的参与打开一个窗口,如关于窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!