Skip to content

Commit bbf72ef

Browse files
committed
added the scrollviewerextensions back in
1 parent 68eda4b commit bbf72ef

File tree

7 files changed

+509
-0
lines changed

7 files changed

+509
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// ******************************************************************
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// This code is licensed under the MIT License (MIT).
4+
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10+
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11+
// ******************************************************************
12+
13+
using System;
14+
using Windows.UI.Xaml;
15+
using Windows.UI.Xaml.Data;
16+
17+
namespace Microsoft.Toolkit.Uwp.SampleApp.Common
18+
{
19+
internal class DoubleTopThicknessConverter : IValueConverter
20+
{
21+
public object Convert(object value, Type targetType, object parameter, string language)
22+
{
23+
return new Thickness(0, (double)value, 0, 0);
24+
}
25+
26+
public object ConvertBack(object value, Type targetType, object parameter, string language)
27+
{
28+
return ((Thickness)value).Top;
29+
}
30+
}
31+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:common="using:Microsoft.Toolkit.Uwp.SampleApp.Common"
4+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
10+
<Page.Resources>
11+
<common:DoubleTopThicknessConverter x:Key="DoubleTopThicknessConverter" />
12+
</Page.Resources>
13+
14+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
15+
<ListView Name="listView"
16+
extensions:ScrollViewerEx.VerticalScrollBarMargin="{Binding MinHeight, ElementName=MyHeaderGrid, Converter={StaticResource DoubleTopThicknessConverter}}">
17+
<ListView.Header>
18+
<controls:ScrollHeader Mode="Sticky">
19+
<Grid x:Name="MyHeaderGrid"
20+
MinHeight="@[Header MinHeight:DoubleSlider:250:150-500]"
21+
Background="{ThemeResource SystemControlAccentAcrylicElementAccentMediumHighBrush}">
22+
<StackPanel HorizontalAlignment="Center"
23+
VerticalAlignment="Center">
24+
<TextBlock Margin="12"
25+
FontSize="48"
26+
FontWeight="Bold"
27+
Foreground="{StaticResource Brush-White}"
28+
Text="Scroll Header"
29+
TextAlignment="Center"
30+
TextWrapping="WrapWholeWords" />
31+
<TextBlock Margin="12,0,12,12"
32+
VerticalAlignment="Center"
33+
Foreground="{StaticResource Brush-White}"
34+
Text="The attached property allows you to assign a Thickness to both vertical and horizontal ScrollBar inside any container. In this example, VerticalScrollBarMargin is bound to StickyHeader's MinHeight. Moving MinHeight's Slider will move the vertical ScrollBar accordingly."
35+
TextAlignment="Center"
36+
TextWrapping="WrapWholeWords" />
37+
</StackPanel>
38+
</Grid>
39+
</controls:ScrollHeader>
40+
</ListView.Header>
41+
<ListView.ItemTemplate>
42+
<DataTemplate>
43+
<Grid MinHeight="100"
44+
Background="{StaticResource Brush-Grey-02}">
45+
<Grid.ColumnDefinitions>
46+
<ColumnDefinition Width="Auto" />
47+
<ColumnDefinition Width="*" />
48+
</Grid.ColumnDefinitions>
49+
<Image x:Name="ToolkitLogo"
50+
Grid.Column="0"
51+
Width="100"
52+
Height="100"
53+
Margin="0,0,24,0"
54+
Source="ms-appx:///Assets/ToolkitLogo.png" />
55+
<TextBlock Grid.Column="1"
56+
VerticalAlignment="Center"
57+
Text="{Binding Title}"
58+
TextTrimming="CharacterEllipsis" />
59+
</Grid>
60+
</DataTemplate>
61+
</ListView.ItemTemplate>
62+
<ListView.ItemContainerStyle>
63+
<Style TargetType="ListViewItem">
64+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
65+
<Setter Property="Padding" Value="12,12,24,12" />
66+
</Style>
67+
</ListView.ItemContainerStyle>
68+
</ListView>
69+
</Grid>
70+
</Page>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<Page x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.ScrollViewerExtensionsPage"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:common="using:Microsoft.Toolkit.Uwp.SampleApp.Common"
5+
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
mc:Ignorable="d">
10+
11+
<Page.Resources>
12+
<common:DoubleTopThicknessConverter x:Key="DoubleTopThicknessConverter" />
13+
</Page.Resources>
14+
15+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
16+
<ListView Name="listView"
17+
extensions:ScrollViewerEx.VerticalScrollBarMargin="{Binding MinHeight, ElementName=MyHeaderGrid, Converter={StaticResource DoubleTopThicknessConverter}}">
18+
<ListView.Header>
19+
<controls:ScrollHeader Mode="Sticky">
20+
<Grid x:Name="MyHeaderGrid"
21+
MinHeight="100"
22+
Background="{ThemeResource SystemControlAccentAcrylicElementAccentMediumHighBrush}">
23+
<StackPanel HorizontalAlignment="Center"
24+
VerticalAlignment="Center">
25+
<TextBlock Margin="12"
26+
FontSize="48"
27+
FontWeight="Bold"
28+
Foreground="{StaticResource Brush-White}"
29+
Text="Scroll Header"
30+
TextAlignment="Center"
31+
TextWrapping="WrapWholeWords" />
32+
<TextBlock Margin="12,0,12,12"
33+
VerticalAlignment="Center"
34+
Foreground="{StaticResource Brush-White}"
35+
Text="The attached property allows you to assign a Thickness to both vertical and horizontal ScrollBar inside any container. In this example, VerticalScrollBarMargin is bound to StickyHeader's MinHeight. Moving MinHeight's Slider will move the vertical ScrollBar accordingly."
36+
TextAlignment="Center"
37+
TextWrapping="WrapWholeWords" />
38+
</StackPanel>
39+
</Grid>
40+
</controls:ScrollHeader>
41+
</ListView.Header>
42+
<ListView.ItemTemplate>
43+
<DataTemplate>
44+
<Grid MinHeight="100"
45+
Background="{StaticResource Brush-Grey-02}">
46+
<Grid.ColumnDefinitions>
47+
<ColumnDefinition Width="Auto" />
48+
<ColumnDefinition Width="*" />
49+
</Grid.ColumnDefinitions>
50+
<Image x:Name="ToolkitLogo"
51+
Grid.Column="0"
52+
Width="100"
53+
Height="100"
54+
Margin="0,0,24,0"
55+
Source="ms-appx:///Assets/ToolkitLogo.png" />
56+
<TextBlock Grid.Column="1"
57+
VerticalAlignment="Center"
58+
Text="{Binding Title}"
59+
TextTrimming="CharacterEllipsis" />
60+
</Grid>
61+
</DataTemplate>
62+
</ListView.ItemTemplate>
63+
<ListView.ItemContainerStyle>
64+
<Style TargetType="ListViewItem">
65+
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
66+
<Setter Property="Padding" Value="12,12,24,12" />
67+
</Style>
68+
</ListView.ItemContainerStyle>
69+
</ListView>
70+
</Grid>
71+
</Page>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ******************************************************************
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// This code is licensed under the MIT License (MIT).
4+
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10+
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11+
// ******************************************************************
12+
13+
using System.Collections.ObjectModel;
14+
using Microsoft.Toolkit.Uwp.SampleApp.Models;
15+
using Microsoft.Toolkit.Uwp.UI.Controls;
16+
using Microsoft.Toolkit.Uwp.UI.Extensions;
17+
using Windows.UI.Xaml;
18+
using Windows.UI.Xaml.Controls;
19+
using Windows.UI.Xaml.Navigation;
20+
21+
namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
22+
{
23+
public sealed partial class ScrollViewerExtensionsPage : IXamlRenderListener
24+
{
25+
private ObservableCollection<Item> _items;
26+
27+
public ScrollViewerExtensionsPage()
28+
{
29+
InitializeComponent();
30+
}
31+
32+
public void OnXamlRendered(FrameworkElement control)
33+
{
34+
var listView = control.FindChildByName("listView") as ListView;
35+
if (listView != null)
36+
{
37+
listView.ItemsSource = _items;
38+
}
39+
}
40+
41+
protected override void OnNavigatedTo(NavigationEventArgs e)
42+
{
43+
base.OnNavigatedTo(e);
44+
45+
// Reset items when revisiting sample.
46+
_items = new ObservableCollection<Item>();
47+
48+
for (var i = 0; i < 1000; i++)
49+
{
50+
_items.Add(new Item() { Title = "Item " + i });
51+
}
52+
}
53+
}
54+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// ******************************************************************
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// This code is licensed under the MIT License (MIT).
4+
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
5+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
6+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
7+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
8+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
10+
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
11+
// ******************************************************************
12+
13+
using Windows.UI.Xaml;
14+
15+
namespace Microsoft.Toolkit.Uwp.UI.Extensions
16+
{
17+
/// <summary>
18+
/// Provides attached dependency properties for the <see cref="Windows.UI.Xaml.Controls.ScrollViewer"/>
19+
/// </summary>
20+
public partial class ScrollViewerEx
21+
{
22+
/// <summary>
23+
/// Attached <see cref="DependencyProperty"/> for binding a <see cref="Windows.UI.Xaml.Thickness"/> for the horizontal <see cref="Windows.UI.Xaml.Controls.Primitives.ScrollBar"/> of a <see cref="Windows.UI.Xaml.Controls.ScrollViewer"/>
24+
/// </summary>
25+
public static readonly DependencyProperty HorizontalScrollBarMarginProperty = DependencyProperty.RegisterAttached("HorizontalScrollBarMargin", typeof(Thickness), typeof(ScrollViewerEx), new PropertyMetadata(null, OnHorizontalScrollBarMarginPropertyChanged));
26+
27+
/// <summary>
28+
/// Attached <see cref="DependencyProperty"/> for binding a <see cref="Windows.UI.Xaml.Thickness"/> for the vertical <see cref="Windows.UI.Xaml.Controls.Primitives.ScrollBar"/> of a <see cref="Windows.UI.Xaml.Controls.ScrollViewer"/>
29+
/// </summary>
30+
public static readonly DependencyProperty VerticalScrollBarMarginProperty = DependencyProperty.RegisterAttached("VerticalScrollBarMargin", typeof(Thickness), typeof(ScrollViewerEx), new PropertyMetadata(null, OnVerticalScrollBarMarginPropertyChanged));
31+
32+
/// <summary>
33+
/// Gets the <see cref="Windows.UI.Xaml.Thickness"/> associated with the specified vertical <see cref="Windows.UI.Xaml.Controls.Primitives.ScrollBar"/> of a <see cref="Windows.UI.Xaml.Controls.ScrollViewer"/>
34+
/// </summary>
35+
/// <param name="obj">The <see cref="FrameworkElement"/> to get the associated <see cref="Windows.UI.Xaml.Thickness"/> from</param>
36+
/// <returns>The <see cref="Windows.UI.Xaml.Thickness"/> associated with the <see cref="FrameworkElement"/></returns>
37+
public static Thickness GetVerticalScrollBarMargin(FrameworkElement obj)
38+
{
39+
return (Thickness)obj.GetValue(VerticalScrollBarMarginProperty);
40+
}
41+
42+
/// <summary>
43+
/// Sets the <see cref="Windows.UI.Xaml.Thickness"/> associated with the specified vertical <see cref="Windows.UI.Xaml.Controls.Primitives.ScrollBar"/> of a <see cref="Windows.UI.Xaml.Controls.ScrollViewer"/>
44+
/// </summary>
45+
/// <param name="obj">The <see cref="FrameworkElement"/> to associate the <see cref="Windows.UI.Xaml.Thickness"/> with</param>
46+
/// <param name="value">The <see cref="Windows.UI.Xaml.Thickness"/> for binding to the <see cref="FrameworkElement"/></param>
47+
public static void SetVerticalScrollBarMargin(FrameworkElement obj, Thickness value)
48+
{
49+
obj.SetValue(VerticalScrollBarMarginProperty, value);
50+
}
51+
52+
/// <summary>
53+
/// Gets the <see cref="Windows.UI.Xaml.Thickness"/> associated with the specified horizontal <see cref="Windows.UI.Xaml.Controls.Primitives.ScrollBar"/> of a <see cref="Windows.UI.Xaml.Controls.ScrollViewer"/>
54+
/// </summary>
55+
/// <param name="obj">The <see cref="FrameworkElement"/> to get the associated <see cref="Windows.UI.Xaml.Thickness"/> from</param>
56+
/// <returns>The <see cref="Windows.UI.Xaml.Thickness"/> associated with the <see cref="FrameworkElement"/></returns>
57+
public static Thickness GetHorizontalScrollBarMargin(FrameworkElement obj)
58+
{
59+
return (Thickness)obj.GetValue(HorizontalScrollBarMarginProperty);
60+
}
61+
62+
/// <summary>
63+
/// Sets the <see cref="Windows.UI.Xaml.Thickness"/> associated with the specified horizontal <see cref="Windows.UI.Xaml.Controls.Primitives.ScrollBar"/> of a <see cref="Windows.UI.Xaml.Controls.ScrollViewer"/>
64+
/// </summary>
65+
/// <param name="obj">The <see cref="FrameworkElement"/> to associate the <see cref="Windows.UI.Xaml.Thickness"/> with</param>
66+
/// <param name="value">The <see cref="Windows.UI.Xaml.Thickness"/> for binding to the <see cref="FrameworkElement"/></param>
67+
public static void SetHorizontalScrollBarMargin(FrameworkElement obj, Thickness value)
68+
{
69+
obj.SetValue(HorizontalScrollBarMarginProperty, value);
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)