私は、ツリービューを含むいくつかのコントロールを持つビュー(MVVM内)を持っています。 ViewModelはdatacontextとModelであり、すべてが今まで正常に動作しています。 **私は2つのケースを持っている:**View Controls表示/非表示WPF MVVM
- は私が私の見解は、ツリービュー項目に対してのContextMenuを表示したいです。
- 以外の場合、それは
は1つのビューで可能これですか、私ならば、私の個人的な仕事のためにそれが良いだろう、この目的のために2つの異なるビューがあるはずツリービュー項目に対してのContextMenuを表示するべきではありませんビューが1つあります。
VMとモデルは、ビューのバインドされたプロパティを持つだけで非常に簡単です。
View.xaml
<UserControl x:Class="SPM.SystemExplorer.View.SystemExplorerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SPM.SystemExplorer.View"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
xmlns:viewModel="clr-namespace:SPM.SystemExplorer.ViewModel"
xmlns:classes="clr-namespace:SPM.SystemExplorer.Classes">
<UserControl.DataContext>
<viewModel:SystemExplorerViewVM></viewModel:SystemExplorerViewVM>
</UserControl.DataContext>
<Grid>
<StackPanel>
<Label Content="{Binding Test}"></Label>
<TreeView Grid.Row="1" ItemsSource="{Binding SystemProjects}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type classes:SystemProject}" ItemsSource="{Binding ParticipantProjects}">
<StackPanel Orientation="Horizontal">
<TreeViewItem Header="{Binding NameOfSystemProject}"></TreeViewItem>
<TreeViewItem Header="{Binding AuthorOfSystemProject}"></TreeViewItem>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type classes:ParticipantProject}">
<StackPanel Orientation="Horizontal">
<TreeViewItem Header="{Binding NameOfParticipantProject}"></TreeViewItem>
<TreeViewItem Header="{Binding AuthorOfParticipantProject}"></TreeViewItem>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
</StackPanel>
</Grid>
あなたが「A」または「B」にSystemExplorerViewVMのプロパティを設定し、データトリガを使用することができます。 – mm8
いくつかの行を書いて例を挙げてください。私はWPFの初心者です。 – Smallestearth
私はそれを正しく説明しなかったと思います。 私が言いたいことは: 実際に私は私の見解について2つのケースを持っています。まず、ツリービュー項目を右クリックすると、私のビューにコンテキストメニューが表示されます。 2番目のケースでは、私は同じビューを持っていますが、ツリービュー項目のコンテキストメニューはありません。 – Smallestearth