Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit a119e89

Browse files
authored
Merge pull request #1842 from github/fixes/1294-style-treeviewitem
Style TreeViewItem
2 parents 6e092aa + afb15d8 commit a119e89

File tree

3 files changed

+150
-3
lines changed

3 files changed

+150
-3
lines changed

src/GitHub.VisualStudio.UI/Styles/ItemsControls.xaml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,151 @@
7474
</Setter.Value>
7575
</Setter>
7676
</Style>
77+
78+
<PathGeometry x:Key="TreeArrow" Figures="M0.5,0.5 L0.5,8.5 L4.5,4.5 z"/>
79+
80+
<Style x:Key="ExpandCollapseToggleStyle" TargetType="{x:Type ToggleButton}">
81+
<Style.Resources>
82+
<PathGeometry x:Key="ArrowCollapsed">
83+
<PathGeometry.Figures>
84+
<PathFigureCollection>
85+
<PathFigure IsClosed="True" IsFilled="True" StartPoint="0.5 0.5">
86+
<PathFigure.Segments>
87+
<PathSegmentCollection>
88+
<LineSegment Point="4.5 4.5" />
89+
<LineSegment Point="0.5 8.5" />
90+
</PathSegmentCollection>
91+
</PathFigure.Segments>
92+
</PathFigure>
93+
</PathFigureCollection>
94+
</PathGeometry.Figures>
95+
</PathGeometry>
96+
<PathGeometry x:Key="ArrowExpanded">
97+
<PathGeometry.Figures>
98+
<PathFigureCollection>
99+
<PathFigure IsClosed="True" IsFilled="True" StartPoint="5.5 0.5">
100+
<PathFigure.Segments>
101+
<PathSegmentCollection>
102+
<LineSegment Point="0.5 5.5" />
103+
<LineSegment Point="5.5 5.5" />
104+
</PathSegmentCollection>
105+
</PathFigure.Segments>
106+
</PathFigure>
107+
</PathFigureCollection>
108+
</PathGeometry.Figures>
109+
</PathGeometry>
110+
</Style.Resources>
111+
<Setter Property="Focusable" Value="False"/>
112+
<Setter Property="Width" Value="16"/>
113+
<Setter Property="Height" Value="16"/>
114+
<Setter Property="Template">
115+
<Setter.Value>
116+
<ControlTemplate TargetType="{x:Type ToggleButton}">
117+
<Border Width="16" Height="16" Background="Transparent">
118+
<Path Name="ExpandPath"
119+
SnapsToDevicePixels="True"
120+
HorizontalAlignment="Center"
121+
VerticalAlignment="Center"
122+
Data="{StaticResource ArrowCollapsed}"
123+
Stroke="{DynamicResource {x:Static vsp:TreeViewColors.GlyphBrushKey}}"/>
124+
</Border>
125+
<ControlTemplate.Triggers>
126+
<Trigger Property="IsChecked" Value="True">
127+
<Setter Property="Data" TargetName="ExpandPath" Value="{StaticResource ArrowExpanded}"/>
128+
<Setter Property="Fill" TargetName="ExpandPath" Value="{DynamicResource {x:Static vsp:TreeViewColors.GlyphBrushKey}}"/>
129+
</Trigger>
130+
<Trigger Property="IsMouseOver" Value="True">
131+
<Setter Property="Stroke" TargetName="ExpandPath" Value="{DynamicResource {x:Static vsp:TreeViewColors.GlyphMouseOverBrushKey}}"/>
132+
</Trigger>
133+
<MultiTrigger>
134+
<MultiTrigger.Conditions>
135+
<Condition Property="IsChecked" Value="True"/>
136+
<Condition Property="IsMouseOver" Value="True"/>
137+
</MultiTrigger.Conditions>
138+
<Setter Property="Fill" TargetName="ExpandPath" Value="{DynamicResource {x:Static vsp:TreeViewColors.GlyphMouseOverBrushKey}}"/>
139+
<Setter Property="Stroke" TargetName="ExpandPath" Value="{DynamicResource {x:Static vsp:TreeViewColors.GlyphMouseOverBrushKey}}"/>
140+
</MultiTrigger>
141+
</ControlTemplate.Triggers>
142+
</ControlTemplate>
143+
</Setter.Value>
144+
</Setter>
145+
</Style>
146+
147+
<Style x:Key="TreeViewItemFocusVisual">
148+
<Setter Property="Control.Template">
149+
<Setter.Value>
150+
<ControlTemplate>
151+
<Rectangle/>
152+
</ControlTemplate>
153+
</Setter.Value>
154+
</Setter>
155+
</Style>
156+
157+
<Style TargetType="TreeViewItem">
158+
<Setter Property="Background" Value="{DynamicResource {x:Static vsp:TreeViewColors.BackgroundBrushKey}}"/>
159+
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
160+
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
161+
<Setter Property="Padding" Value="1,0,0,0"/>
162+
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsp:TreeViewColors.BackgroundTextBrushKey}}"/>
163+
<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
164+
<Setter Property="Template">
165+
<Setter.Value>
166+
<ControlTemplate TargetType="{x:Type TreeViewItem}">
167+
<Grid>
168+
<Grid.ColumnDefinitions>
169+
<ColumnDefinition MinWidth="19" Width="Auto"/>
170+
<ColumnDefinition Width="Auto"/>
171+
<ColumnDefinition Width="*"/>
172+
</Grid.ColumnDefinitions>
173+
<Grid.RowDefinitions>
174+
<RowDefinition Height="Auto"/>
175+
<RowDefinition/>
176+
</Grid.RowDefinitions>
177+
<ToggleButton x:Name="Expander"
178+
ClickMode="Press"
179+
IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
180+
Style="{StaticResource ExpandCollapseToggleStyle}"/>
181+
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
182+
<ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
183+
</Border>
184+
<ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="1"/>
185+
</Grid>
186+
<ControlTemplate.Triggers>
187+
<Trigger Property="IsExpanded" Value="false">
188+
<Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
189+
</Trigger>
190+
<Trigger Property="HasItems" Value="false">
191+
<Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
192+
</Trigger>
193+
<Trigger Property="IsSelected" Value="true">
194+
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static vsp:TreeViewColors.SelectedItemActiveBrushKey}}"/>
195+
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsp:TreeViewColors.SelectedItemActiveTextBrushKey}}"/>
196+
</Trigger>
197+
<MultiTrigger>
198+
<MultiTrigger.Conditions>
199+
<Condition Property="IsSelected" Value="true"/>
200+
<Condition Property="IsSelectionActive" Value="false"/>
201+
</MultiTrigger.Conditions>
202+
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static vsp:TreeViewColors.SelectedItemInactiveBrushKey}}"/>
203+
<Setter Property="Foreground" Value="{DynamicResource {x:Static vsp:TreeViewColors.SelectedItemInactiveTextBrushKey}}"/>
204+
</MultiTrigger>
205+
<Trigger Property="IsEnabled" Value="false">
206+
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
207+
</Trigger>
208+
</ControlTemplate.Triggers>
209+
</ControlTemplate>
210+
</Setter.Value>
211+
</Setter>
212+
<Style.Triggers>
213+
<Trigger Property="VirtualizingPanel.IsVirtualizing" Value="true">
214+
<Setter Property="ItemsPanel">
215+
<Setter.Value>
216+
<ItemsPanelTemplate>
217+
<VirtualizingStackPanel/>
218+
</ItemsPanelTemplate>
219+
</Setter.Value>
220+
</Setter>
221+
</Trigger>
222+
</Style.Triggers>
223+
</Style>
77224
</ResourceDictionary>

src/GitHub.VisualStudio/Views/GitHubPane/PullRequestDetailView.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270
<!-- Put the changes tree outside its expander, so it can scroll horizontally
271271
while the header remains fixed -->
272272
<local:PullRequestFilesView DataContext="{Binding Files}"
273+
Margin="8,0,0,0"
273274
Visibility="{Binding ElementName=changesSection, Path=IsExpanded, Converter={ghfvs:BooleanToVisibilityConverter}}"/>
274275
</ghfvs:ScrollingVerticalStackPanel>
275276
</ScrollViewer>

src/GitHub.VisualStudio/Views/GitHubPane/PullRequestFilesView.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@
4343
MouseDoubleClick="changesTree_MouseDoubleClick"
4444
MouseRightButtonDown="changesTree_MouseRightButtonDown">
4545
<TreeView.ItemContainerStyle>
46-
<Style TargetType="TreeViewItem">
46+
<Style TargetType="TreeViewItem" BasedOn="{StaticResource {x:Type TreeViewItem}}">
4747
<Setter Property="IsExpanded" Value="True"/>
48-
<Setter Property="Foreground" Value="{DynamicResource GitHubVsWindowText}"/>
4948
</Style>
5049
</TreeView.ItemContainerStyle>
5150
<TreeView.Resources>
@@ -67,7 +66,7 @@
6766
KeyboardNavigation.DirectionalNavigation="None">
6867

6968
<imaging:CrispImage Moniker="{Binding Converter={StaticResource FileNameToImageMonikerConverter}, Path=FileName}"
70-
Width="16" Height="16" Margin="0,0,0,2"/>
69+
Width="16" Height="16" Margin="0,2"/>
7170

7271
<TextBlock Text="{Binding FileName}" Margin="4 2" VerticalAlignment="Center">
7372
<TextBlock.Style>

0 commit comments

Comments
 (0)