/
InfiniteScrollList.xaml
436 lines (415 loc) · 17.7 KB
/
InfiniteScrollList.xaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<UserControl
x:Class="NuGet.PackageManagement.UI.InfiniteScrollList"
x:Name="_infiniteScrollList"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:nuget="clr-namespace:NuGet.PackageManagement.UI"
xmlns:common="clr-namespace:NuGet.VisualStudio;assembly=NuGet.VisualStudio.Common"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0"
mc:Ignorable="d"
d:DesignHeight="200"
d:DesignWidth="500">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<nuget:SharedResources />
</ResourceDictionary.MergedDictionaries>
<nuget:InfiniteScrollListItemStyleSelector
x:Key="itemStyleSelector" />
<nuget:PackageLevelToGroupNameConverter
x:Key="PackageLevelToGroupNameConverter" />
<nuget:PackageLevelGroupToBooleanConverter
x:Key="PackageLevelGroupToBooleanConverter" />
<DataTemplate
DataType="{x:Type nuget:PackageDependencyMetadata}">
<TextBlock
Text="{Binding}" />
</DataTemplate>
<DataTemplate
DataType="{x:Type nuget:PackageItemViewModel}">
<nuget:PackageItemControl
DataContext="{Binding}" />
</DataTemplate>
<DataTemplate
DataType="{x:Type nuget:LoadingStatusIndicator}">
<Grid
Margin="0,8">
<TextBlock
Name="_noItemsFound"
FontStyle="Italic"
HorizontalAlignment="Center"
Text="{x:Static nuget:Resources.Text_NoPackagesFound}"
Visibility="Collapsed" />
<Grid
Name="_progressBar"
Visibility="Collapsed"
HorizontalAlignment="Center"
Height="22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<nuget:Spinner
Grid.Column="0"
Width="16"
Height="16"
Margin="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Visibility="{Binding Visibility,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}, AncestorLevel=1}}"/>
<TextBlock
Grid.Column="1"
Text="{Binding Path=LoadingMessage}"
HorizontalAlignment="Left"
VerticalAlignment="Center"/>
</Grid>
</Grid>
<DataTemplate.Triggers>
<DataTrigger
Binding="{Binding Path=Status}"
Value="Loading">
<Setter
TargetName="_progressBar"
Property="Visibility"
Value="Visible" />
</DataTrigger>
<DataTrigger
Binding="{Binding Path=Status}"
Value="Ready">
<Setter
TargetName="_progressBar"
Property="Visibility"
Value="Visible" />
</DataTrigger>
<DataTrigger
Binding="{Binding Path=Status}"
Value="NoItemsFound">
<Setter
TargetName="_noItemsFound"
Property="Visibility"
Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<!-- Template used by ListBoxItem that represents a package. -->
<ControlTemplate
x:Key="ListBoxItemTemplate"
TargetType="{x:Type ListBoxItem}">
<Border
x:Name="Bd"
BorderThickness="0"
Background="{TemplateBinding Background}"
Padding="0"
SnapsToDevicePixels="true">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<!-- set the background for IsEnabled == false -->
<Trigger
Property="IsEnabled"
Value="false">
<Setter
Property="Background"
TargetName="Bd"
Value="{DynamicResource {x:Static nuget:Brushes.ListPaneBackground}}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition
Property="IsMouseOver"
Value="True" />
</MultiTrigger.Conditions>
<Setter
Property="Background"
TargetName="Bd"
Value="{DynamicResource {x:Static nuget:Brushes.ContentMouseOverBrushKey}}" />
<Setter
Property="TextBlock.Foreground"
Value="{DynamicResource {x:Static nuget:Brushes.ContentMouseOverTextBrushKey}}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition
Property="Selector.IsSelectionActive"
Value="False" />
<Condition
Property="IsSelected"
Value="True" />
</MultiTrigger.Conditions>
<Setter
Property="Background"
TargetName="Bd"
Value="{DynamicResource {x:Static nuget:Brushes.ContentInactiveSelectedBrushKey}}" />
<Setter
Property="TextBlock.Foreground"
Value="{DynamicResource {x:Static nuget:Brushes.ContentInactiveSelectedTextBrushKey}}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition
Property="Selector.IsSelectionActive"
Value="True" />
<Condition
Property="IsSelected"
Value="True" />
</MultiTrigger.Conditions>
<Setter
Property="Background"
TargetName="Bd"
Value="{DynamicResource {x:Static nuget:Brushes.ContentSelectedBrushKey}}" />
<Setter
Property="TextBlock.Foreground"
TargetName="Bd"
Value="{DynamicResource {x:Static nuget:Brushes.ContentSelectedTextBrushKey}}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- Template used by the LoadingIndicator. We use it to disable the background change when mouse hovers over it. -->
<ControlTemplate
x:Key="LoadingIndicatorListBoxItemTemplate"
TargetType="{x:Type ListBoxItem}">
<Border
x:Name="Bd"
BorderThickness="0"
Background="{DynamicResource {x:Static nuget:Brushes.ListPaneBackground}}"
Padding="0"
SnapsToDevicePixels="true">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
<!-- the base style of the ListBoxItem. -->
<Style
x:Key="listBoxItemStyle"
TargetType="{x:Type ListBoxItem}">
<Setter
Property="Padding"
Value="0" />
<Setter
Property="SnapsToDevicePixels"
Value="True" />
<Setter
Property="HorizontalContentAlignment"
Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter
Property="VerticalContentAlignment"
Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter
Property="Background"
Value="Transparent" />
</Style>
<!-- the style of the ListBoxItem when the item is the loading status indicator. -->
<Style
x:Key="loadingStatusIndicatorStyle"
TargetType="{x:Type ListBoxItem}"
BasedOn="{StaticResource listBoxItemStyle}">
<Setter
Property="Template"
Value="{StaticResource LoadingIndicatorListBoxItemTemplate}" />
<Setter
Property="Focusable"
Value="False" />
</Style>
<!-- the style of the ListBoxItem when the item is a package. -->
<Style
x:Key="packageItemStyle"
TargetType="{x:Type ListBoxItem}"
BasedOn="{StaticResource listBoxItemStyle}">
<!--
Note that we cannot set the template property in xaml list this:
<Setter Property="Template" Value="{StaticResource ListBoxItemTemplate}" />
The reason is that the template references resources defined in VisualStudio, which are obviously not
available when this is used in the standalone mode, i.e. outside of VisualStudio. So the setter is
added by code when Standalone == false.
-->
</Style>
<Style TargetType="FrameworkElement" x:Key="FadeAnimationStyle">
<Setter Property="Visibility" Value="Hidden"/>
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From="0.0" To="1.0" Duration="0:0:0.7"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
<!--
This scrollviewer template has one change from the default - a -22 margin on the verical srollbar.
This enables the loadingStatusBar to appear to be in the listbox.
-->
<ControlTemplate x:Key="ScrollViewerWithScrollBarExtraLargeOnTop" TargetType="{x:Type ScrollViewer}">
<Grid x:Name="Grid" Background="{TemplateBinding Background}" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle x:Name="Corner" Grid.Column="1" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Grid.Row="1"/>
<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" Margin="{TemplateBinding Padding}" Grid.Row="0"/>
<ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="1" Maximum="{TemplateBinding ScrollableHeight}" Margin="0,-22,0,0" Minimum="0" Grid.Row="0" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}"/>
<ScrollBar x:Name="PART_HorizontalScrollBar" AutomationProperties.AutomationId="HorizontalScrollBar" Cursor="Arrow" Grid.Column="0" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0" Orientation="Horizontal" Grid.Row="1" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/>
</Grid>
</ControlTemplate>
<MultiBinding x:Key="GroupHeaderMultiBinding" Converter="{StaticResource PackageLevelToGroupNameConverter}">
<Binding Path="Name" />
<Binding ElementName="_infiniteScrollList" Path="TopLevelPackageCount" />
<Binding ElementName="_infiniteScrollList" Path="TransitivePackageCount" />
</MultiBinding>
<Style
x:Key="ExpanderStyle"
TargetType="{x:Type Expander}"
BasedOn="{StaticResource {x:Type Expander}}">
<Setter Property="Header" Value="{StaticResource GroupHeaderMultiBinding}" />
<Setter Property="Tag" Value="{Binding Name}" /> <!-- Store unconverted enum PackageLevel-->
<Setter Property="Foreground" Value="{DynamicResource {x:Static nuget:Brushes.UIText}}" />
</Style>
<ControlTemplate
x:Key="GroupedListItemControlTemplate"
TargetType="{x:Type GroupItem}">
<Expander
Style="{StaticResource ExpanderStyle}"
Expanded="Expander_ExpansionStateToggled"
Collapsed="Expander_ExpansionStateToggled"
IsExpanded="True">
<ItemsPresenter />
</Expander>
</ControlTemplate>
<ControlTemplate
x:Key="GroupedListItemNoExpanderControlTemplate"
TargetType="{x:Type GroupItem}">
<ItemsPresenter />
</ControlTemplate>
<Style
x:Key="GroupedListContainerStyle"
TargetType="{x:Type GroupItem}">
<Setter Property="Template" Value="{StaticResource GroupedListItemControlTemplate}" />
<Setter Property="AutomationProperties.Name" Value="{StaticResource GroupHeaderMultiBinding}" />
<Style.Triggers>
<!--This data trigger is when a new group is added, if the group is not of type PackageLevel
it won't add a expander header and will instead show it flat in the list -->
<DataTrigger Binding="{Binding Converter={StaticResource PackageLevelGroupToBooleanConverter}}" Value="False">
<Setter Property="Template" Value="{StaticResource GroupedListItemNoExpanderControlTemplate}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</UserControl.Resources>
<DockPanel LastChildFill="True">
<Border
x:Name="_updateButtonContainer"
DockPanel.Dock="Top"
BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}"
BorderThickness="0,0,0,1"
Background="{DynamicResource {x:Static nuget:Brushes.LegalMessageBackground}}"
Visibility="Collapsed">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<CheckBox
x:Name="_selectAllPackages"
Grid.Column="0"
Margin="4, 8"
VerticalAlignment="Center"
Checked="SelectAllPackagesCheckBox_Checked"
Unchecked="SelectAllPackagesCheckBox_Unchecked"
Foreground="{DynamicResource {x:Static nuget:Brushes.UIText}}"
Content="{x:Static nuget:Resources.Checkbox_SelectAllPackages}" />
<Button
x:Name="_updateButton"
Grid.Column="2"
MinWidth="100"
MinHeight="24"
Margin="24,8"
VerticalAlignment="Center"
Click="_updateButton_Click"
Content="{x:Static nuget:Resources.Button_Update}" />
</Grid>
</Border>
<Grid
DockPanel.Dock="Top"
Background="{DynamicResource {x:Static nuget:Brushes.ListPaneBackground}}"
Height="22">
<nuget:LoadingStatusBar
x:Name="_loadingStatusBar"
ShowMoreResultsClick="_loadingStatusBar_ShowMoreResultsClick"
DismissClick="_loadingStatusBar_DismissClick"
Style="{StaticResource FadeAnimationStyle}"
Visibility="Hidden"/>
<!--
Special TextBlock to report loading status to assistive technologies (narrator).
Code behind changes to the Text property will trigger a narrator event.
-->
<vs:LiveTextBlock
x:Name="_ltbLoading"
Visibility="Collapsed"
IsFrequencyLimited="True"
Focusable="False"
AutomationProperties.IsOffscreenBehavior="Offscreen" />
</Grid>
<nuget:InfiniteScrollListBox
d:DataContext="{d:DesignData Source=/Design/PackageItemListViewSampleData.xaml,IsDesignTimeCreatable=True}"
x:Name="_list"
AutomationProperties.Name="{x:Static nuget:Resources.Accessibility_Packages}"
DockPanel.Dock="Bottom"
PreviewKeyUp="List_PreviewKeyUp"
Background="{DynamicResource {x:Static nuget:Brushes.ListPaneBackground}}"
Foreground="{DynamicResource {x:Static nuget:Brushes.UIText}}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ItemContainerStyleSelector="{DynamicResource itemStyleSelector}"
VirtualizingPanel.IsVirtualizing="true"
VirtualizingPanel.VirtualizationMode="Recycling"
VirtualizingPanel.CacheLength="1,2"
VirtualizingPanel.CacheLengthUnit="Page"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
BorderThickness="0,0,0,0"
HorizontalContentAlignment="Stretch"
SelectionChanged="List_SelectionChanged"
Loaded="List_Loaded"
ItemsSource="{Binding}">
<ListBox.GroupStyle>
<GroupStyle
ContainerStyle="{StaticResource GroupedListContainerStyle}" />
</ListBox.GroupStyle>
<!-- set the template to disable the background change when the IsEnabled is false. -->
<ListBox.Template>
<ControlTemplate
TargetType="{x:Type ListBox}">
<Border
x:Name="Bd"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="1"
SnapsToDevicePixels="true">
<ScrollViewer
Template="{StaticResource ScrollViewerWithScrollBarExtraLargeOnTop}"
Focusable="false"
Padding="{TemplateBinding Padding}">
<ItemsPresenter
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</ScrollViewer>
</Border>
</ControlTemplate>
</ListBox.Template>
</nuget:InfiniteScrollListBox>
</DockPanel>
</UserControl>