TreeView.xaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <ResourceDictionary
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. mc:Ignorable="d">
  7. <SolidColorBrush x:Key="TreeView_BG_MouseOver" Color="#FFD6DCE5"/>
  8. <SolidColorBrush x:Key="TreeView_BG_Select" Color="#FF47A2E7"/>
  9. <Style x:Key="TreeViewItemFocusVisual"/>
  10. <PathGeometry x:Key="TreeArrow" Figures="M0,0 L0,6 L6,0 z"/>
  11. <Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
  12. <Setter Property="Focusable" Value="False"/>
  13. <Setter Property="Width" Value="16"/>
  14. <Setter Property="Height" Value="16"/>
  15. <Setter Property="Template">
  16. <Setter.Value>
  17. <ControlTemplate TargetType="{x:Type ToggleButton}">
  18. <Border Background="#00FFFFFF" Width="16" Height="16" Padding="3,0" Cursor="Hand">
  19. <Grid>
  20. <Grid Background="Black" Margin="-5" Opacity="0"/>
  21. <Path x:Name="ExpandPath" Fill="Gray" Data="{StaticResource TreeArrow}" HorizontalAlignment="Left" VerticalAlignment="Center">
  22. <Path.RenderTransform>
  23. <RotateTransform Angle="135" CenterX="3" CenterY="3"/>
  24. </Path.RenderTransform>
  25. </Path>
  26. </Grid>
  27. </Border>
  28. <ControlTemplate.Triggers>
  29. <Trigger Property="IsMouseOver" Value="True">
  30. <Setter Property="Fill" TargetName="ExpandPath" Value="#FFFFBB00"/>
  31. </Trigger>
  32. <Trigger Property="IsChecked" Value="True">
  33. <Setter Property="RenderTransform" TargetName="ExpandPath">
  34. <Setter.Value>
  35. <RotateTransform Angle="180" CenterX="3" CenterY="3"/>
  36. </Setter.Value>
  37. </Setter>
  38. <Setter Property="Fill" TargetName="ExpandPath" Value="Black"/>
  39. </Trigger>
  40. <Trigger Property="IsEnabled" Value="false">
  41. <Setter Property="Fill" TargetName="ExpandPath" Value="#FF9A9A9A"/>
  42. </Trigger>
  43. </ControlTemplate.Triggers>
  44. </ControlTemplate>
  45. </Setter.Value>
  46. </Setter>
  47. </Style>
  48. <Style x:Key="{x:Type TreeViewItem}" TargetType="{x:Type TreeViewItem}">
  49. <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  50. <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
  51. <Setter Property="Padding" Value="1,0,0,0"/>
  52. <Setter Property="FontFamily" Value="Arial"/>
  53. <Setter Property="Background" Value="{DynamicResource TreeView_BG_MouseOver}"/>
  54. <Setter Property="Foreground" Value="{DynamicResource FG_Black}"/>
  55. <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
  56. <Setter Property="FontSize" Value="16"/>
  57. <Setter Property="Template">
  58. <Setter.Value>
  59. <ControlTemplate TargetType="{x:Type TreeViewItem}">
  60. <Grid SnapsToDevicePixels="true">
  61. <Grid.ColumnDefinitions>
  62. <ColumnDefinition MinWidth="16" Width="Auto"/>
  63. <ColumnDefinition Width="Auto"/>
  64. <ColumnDefinition Width="*"/>
  65. </Grid.ColumnDefinitions>
  66. <Grid.RowDefinitions>
  67. <RowDefinition Height="Auto" MinHeight="24"/>
  68. <RowDefinition/>
  69. </Grid.RowDefinitions>
  70. <Border x:Name="Text_BG" Grid.ColumnSpan="3" Background="{TemplateBinding Background}" Margin="-2,2,1,1" Opacity="0"/>
  71. <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" ClickMode="Press" IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
  72. <Grid x:Name="TreeViewHeader" Grid.Column="1" HorizontalAlignment="Left" Cursor="Hand">
  73. <ContentPresenter x:Name="PART_Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" VerticalAlignment="Center" Margin="2,0,5,0"/>
  74. </Grid>
  75. <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="1"/>
  76. </Grid>
  77. <ControlTemplate.Triggers>
  78. <Trigger Property="IsMouseOver" SourceName="TreeViewHeader" Value="True">
  79. <Setter Property="Opacity" TargetName="Text_BG" Value="1"/>
  80. <Setter Property="Foreground" Value="{DynamicResource FG_Blue}"/>
  81. </Trigger>
  82. <Trigger Property="IsSelected" Value="True">
  83. <Setter Property="BorderThickness" TargetName="Text_BG" Value="0"/>
  84. <Setter Property="Opacity" TargetName="Text_BG" Value="1"/>
  85. <Setter Property="Foreground" Value="{DynamicResource FG_White}"/>
  86. <Setter Property="Background" TargetName="Text_BG" Value="{DynamicResource TreeView_BG_Select}"/>
  87. </Trigger>
  88. <Trigger Property="IsExpanded" Value="false">
  89. <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
  90. </Trigger>
  91. <Trigger Property="HasItems" Value="false">
  92. <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
  93. </Trigger>
  94. <Trigger Property="IsEnabled" Value="false">
  95. <Setter Property="Foreground" Value="#FF9A9A9A"/>
  96. </Trigger>
  97. </ControlTemplate.Triggers>
  98. </ControlTemplate>
  99. </Setter.Value>
  100. </Setter>
  101. <Style.Triggers>
  102. <Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
  103. <Setter Property="ItemsPanel">
  104. <Setter.Value>
  105. <ItemsPanelTemplate>
  106. <VirtualizingStackPanel/>
  107. </ItemsPanelTemplate>
  108. </Setter.Value>
  109. </Setter>
  110. </Trigger>
  111. </Style.Triggers>
  112. </Style>
  113. <Style x:Key="TreeView-SecondFloor" TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
  114. <Setter Property="FontSize" Value="14"/>
  115. </Style>
  116. <Style x:Key="{x:Type TreeView}" TargetType="{x:Type TreeView}">
  117. <Setter Property="Background" Value="Transparent"/>
  118. <Setter Property="OverridesDefaultStyle" Value="True"/>
  119. <Setter Property="SnapsToDevicePixels" Value="True"/>
  120. <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
  121. <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
  122. <Setter Property="Template">
  123. <Setter.Value >
  124. <ControlTemplate TargetType="{x:Type TreeView}" >
  125. <Border x:Name = "Border" CornerRadius="1" BorderThickness="1">
  126. <ScrollViewer Focusable="False" CanContentScroll="False" Padding="4">
  127. <ItemsPresenter/>
  128. </ScrollViewer>
  129. </Border>
  130. </ControlTemplate>
  131. </Setter.Value>
  132. </Setter>
  133. </Style>
  134. <HierarchicalDataTemplate x:Key="FolderTemplate" ItemsSource="{Binding Files}">
  135. <StackPanel Orientation="Horizontal" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}, Path=DataContext}">
  136. <Image x:Name="ExpandImage" Source="Folder_Close.png" Width="14" Height="12" Margin="2,0,0,0" VerticalAlignment="Center"/>
  137. <TextBlock Text="{Binding Name}" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left"/>
  138. <StackPanel.ContextMenu>
  139. <ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
  140. <MenuItem Header="新建菜单文件" Command="{Binding NewSequenceCommand}"></MenuItem>
  141. <Separator/>
  142. <MenuItem Header="新建文件夹" Command="{Binding NewFolderCommand}">
  143. </MenuItem>
  144. <MenuItem Header="删除文件夹" Command="{Binding DeleteFolderCommand}">
  145. </MenuItem>
  146. </ContextMenu>
  147. </StackPanel.ContextMenu>
  148. </StackPanel>
  149. <HierarchicalDataTemplate.Triggers>
  150. <Trigger Property="IsEnabled" Value="false">
  151. <Setter Property="Image.Source" TargetName="ExpandImage" Value="Folder_Unable.png"/>
  152. </Trigger>
  153. <!--<DataTrigger Binding="{Binding HasItems}" Value="True">
  154. <Setter Property="Image.Source" TargetName="ExpandImage" Value="Folder_Open.png"/>
  155. </DataTrigger>-->
  156. </HierarchicalDataTemplate.Triggers>
  157. </HierarchicalDataTemplate>
  158. <HierarchicalDataTemplate x:Key="FileTemplate" ItemsSource="{Binding Files}">
  159. <StackPanel Orientation="Horizontal" Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}, Path=DataContext}">
  160. <Path Data="M0.5,5.125 L5.125,5.125 5.125,0.5 M5.1,0.5 L15.5,0.5 15.5,19.5 0.5,19.5 C0.5,14.7 0.5,10 0.5,5.1 2,3.6 3.6,2 5.1,0.5 z M8.1,8.5 L8.2,8.5 z M8.1,11.5 L8.2,11.5 z M8.1,14.5 L8.2,14.5 z" Fill="#FFF3F3F3" HorizontalAlignment="Left" Stretch="Fill" Stroke="#FF454545" Width="13" Height="16"/>
  161. <TextBlock Text="{Binding Name}" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left"/>
  162. <StackPanel.ContextMenu>
  163. <ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, RelativeSource={RelativeSource Self}}">
  164. <MenuItem Header="另存为" Command="{Binding SaveAsCommand}">
  165. </MenuItem>
  166. <MenuItem Header="重命名菜单文件" Command="{Binding RenameCommand}">
  167. </MenuItem>
  168. <MenuItem Header="删除菜单文件" Command="{Binding DeleteSequenceCommand}">
  169. </MenuItem>
  170. </ContextMenu>
  171. </StackPanel.ContextMenu>
  172. </StackPanel>
  173. </HierarchicalDataTemplate>
  174. </ResourceDictionary>