2016-04-08 9 views
0

アプリケーションのナビゲーションや廃棄時に状態を保持するために、ツリービューの状態を保存する方法があります(拡張プロパティと選択プロパティ)。WinRT XAML Toolkit TreeView保存状態

意味的には2つの異なるメーターなので、itemsourceにそのような情報を追加したくありません。 ItemSourceは、展開された状態と何の関係も持た​​ないドメインオブジェクトです。

ありがとうございます。

答えて

0

あなたは、このようなツリーの各ノードに関連付けられたビューモデルの中にあるものの情報を保存することができます:

public class PersonViewModel 
{ 
    readonly List<Person> _children = new List<Person>(); 
    private bool _isExpanded; 

    public IList<Person> Children 
    { 
     get { return _children; } 
    } 

    public string Name { get; set; } 

    /// <summary> 
    /// Gets/sets whether the TreeViewItem 
    /// associated with this object is expanded. 
    /// </summary> 
    public bool IsExpanded 
    { 
     get { return _isExpanded; } 
     set 
     { 
      if (value != _isExpanded) 
      { 
       _isExpanded = value; 
       this.OnPropertyChanged("IsExpanded"); 
      }    
     } 
    } 
} 

次にあなたが見ると、これらのプロパティをバインドすることができます。

<TreeView ItemsSource="{Binding Persons}"> 
    <TreeView.ItemContainerStyle> 
     <Style TargetType="{x:Type PersonViewModel}"> 
     <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /> 
     <Style.Triggers> 
      <Trigger Property="IsSelected" Value="True"> 
       <Setter Property="FontWeight" Value="Bold" /> 
      </Trigger> 
     </Style.Triggers> 
     </Style> 
    </TreeView.ItemContainerStyle> 

    <TreeView.Resources> 
     <HierarchicalDataTemplate DataType="{x:Type local:PersonViewModel}" 
            ItemsSource="{Binding Children}"> 
      <StackPanel> 
       <TextBlock Text="{Binding Name}" /> 
      </StackPanel> 
     </HierarchicalDataTemplate> 

     <DataTemplate DataType="{x:Type local:PersonViewModel}"> 
      <StackPanel>     
       <TextBlock Text="{Binding Name}" /> 
      </StackPanel> 
     </DataTemplate> 
    </TreeView.Resources> 
</TreeView> 

http://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode


しかし、あなたが探している:あなたはおそらく、あなたが必要としないので、のContentPresenterを使用してメニューから[ナビゲーションを分離したい

メニューの状態を保存します。

<Page 
    x:Class="DataCloner.Uwp.Shell" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:DataCloner.Uwp" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:views="using:DataCloner.Uwp.Views" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="auto"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 
     <Grid> 
      <views:TopBarView/> 
     </Grid> 
     <SplitView x:Name="rootSplitView" Content="{Binding myContentView}" DisplayMode="Inline" IsPaneOpen="True" Grid.Row="1" 
       OpenPaneLength="300"> 
      <SplitView.Pane> 
       <views:MenuPanelView/> 
      </SplitView.Pane>     
     </SplitView> 
    </Grid> 
</Page> 
関連する問題