Skip to content

Commit

Permalink
Make scrool controls part of the sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuavio committed Jun 28, 2021
1 parent 3f4f130 commit 3f1b3fd
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,49 @@
</Page.Resources>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListView x:Name="SampleListView"
Grid.Column="0"
Margin="12"
ui:ListViewExtensions.AlternateColor="#33AAAAAA"
ui:ListViewExtensions.AlternateItemTemplate="{StaticResource AlternateTemplate}"
ui:ListViewExtensions.Command="{StaticResource SampleCommand}"
ui:ListViewExtensions.ItemContainerStretchDirection="Both"
IsItemClickEnabled="True"
ItemTemplate="{StaticResource NormalTemplate}" />

<StackPanel Grid.Column="1" Margin="5,0,5,0" Width="200">
<TextBox x:Name="IndexInput"
Header="Index"
InputScope="Number"
Text="0" />
<ComboBox x:Name="ItemPlacementInput"
Header="Item Placement"
SelectedIndex="0">
<x:String>Default</x:String>
<x:String>Left</x:String>
<x:String>Top</x:String>
<x:String>Center</x:String>
<x:String>Right</x:String>
<x:String>Bottom</x:String>
</ComboBox>
<CheckBox x:Name="DisableAnimationInput"
Content="Disable Animation"
IsChecked="False" />
<CheckBox x:Name="ScrollIfVisibileInput"
Content="Scroll If Visible"
IsChecked="True" />
<TextBox x:Name="AdditionalHorizontalOffsetInput"
Header="Horizontal Offset"
InputScope="Number"
Text="0" />
<TextBox x:Name="AdditionalVerticalOffsetInput"
Header="Vertical Offset"
InputScope="Number"
Text="0" />
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -15,12 +15,12 @@ namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
public sealed partial class ListViewExtensionsPage : Page, IXamlRenderListener
{
private ListView sampleListView;
private TextBlock indexInput;
private TextBlock itemPlacementInput;
private TextBox indexInput;
private ComboBox itemPlacementInput;
private CheckBox disableAnimationInput;
private CheckBox scrollIfVisibileInput;
private TextBlock additionalHorizontalOffsetInput;
private TextBlock additionalVerticalOffsetInput;
private TextBox additionalHorizontalOffsetInput;
private TextBox additionalVerticalOffsetInput;

public ListViewExtensionsPage()
{
Expand All @@ -31,12 +31,12 @@ public ListViewExtensionsPage()
public void OnXamlRendered(FrameworkElement control)
{
sampleListView = control.FindChild("SampleListView") as ListView;
indexInput = control.FindChild("IndexInput") as TextBlock;
itemPlacementInput = control.FindChild("ItemPlacementInput") as TextBlock;
indexInput = control.FindChild("IndexInput") as TextBox;
itemPlacementInput = control.FindChild("ItemPlacementInput") as ComboBox;
disableAnimationInput = control.FindChild("DisableAnimationInput") as CheckBox;
scrollIfVisibileInput = control.FindChild("ScrollIfVisibileInput") as CheckBox;
additionalHorizontalOffsetInput = control.FindChild("AdditionalHorizontalOffsetInput") as TextBlock;
additionalVerticalOffsetInput = control.FindChild("AdditionalVerticalOffsetInput") as TextBlock;
additionalHorizontalOffsetInput = control.FindChild("AdditionalHorizontalOffsetInput") as TextBox;
additionalVerticalOffsetInput = control.FindChild("AdditionalVerticalOffsetInput") as TextBox;

if (sampleListView != null)
{
Expand All @@ -51,12 +51,22 @@ private void Load()
{
SampleController.Current.RegisterNewCommand("Start Smooth Scroll", (sender, args) =>
{
var index = int.Parse(indexInput?.Text);
var itemPlacement = (ItemPlacement)Enum.Parse(typeof(ItemPlacement), itemPlacementInput?.Text);
var disableAnimation = disableAnimationInput?.IsChecked ?? false;
var scrollIfVisibile = scrollIfVisibileInput?.IsChecked ?? true;
var additionalHorizontalOffset = int.Parse(additionalHorizontalOffsetInput?.Text);
var additionalVerticalOffset = int.Parse(additionalVerticalOffsetInput?.Text);
var index = int.TryParse(indexInput.Text, out var i) ? i : 0;
var itemPlacement = itemPlacementInput.SelectedItem switch
{
"Default" => UI.ItemPlacement.Default,
"Left" => UI.ItemPlacement.Left,
"Top" => UI.ItemPlacement.Top,
"Center" => UI.ItemPlacement.Center,
"Right" => UI.ItemPlacement.Right,
"Bottom" => UI.ItemPlacement.Bottom,
_ => UI.ItemPlacement.Default
};

var disableAnimation = disableAnimationInput.IsChecked ?? false;
var scrollIfVisibile = scrollIfVisibileInput.IsChecked ?? true;
var additionalHorizontalOffset = int.TryParse(additionalHorizontalOffsetInput.Text, out var ho) ? ho : 0;
var additionalVerticalOffset = int.TryParse(additionalVerticalOffsetInput.Text, out var vo) ? vo : 0;
sampleListView.SmoothScrollIntoViewWithIndex(index, itemPlacement, disableAnimation, scrollIfVisibile, additionalHorizontalOffset, additionalVerticalOffset);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
</Page.Resources>

<Grid>
<TextBlock x:Name="IndexInput" x:Load="False" Text="@[Index:Slider:100:0-200]" Visibility="Collapsed"></TextBlock>
<TextBlock x:Name="ItemPlacementInput" x:Load="False" Text="@[Item Placement:Enum:ItemPlacement.Default]" Visibility="Collapsed"></TextBlock>
<CheckBox x:Name="DisableAnimationInput" x:Load="False" IsChecked="@[Disable Animation:Bool:False]" Visibility="Collapsed"></CheckBox>
<CheckBox x:Name="ScrollIfVisibileInput" x:Load="False" IsChecked="@[Scroll If Visibile:Bool:True]" Visibility="Collapsed"></CheckBox>
<TextBlock x:Name="AdditionalHorizontalOffsetInput" x:Load="False" Text="@[Additional Horizontal Offset:Slider:0:-500-500]" Visibility="Collapsed"></TextBlock>
<TextBlock x:Name="AdditionalVerticalOffsetInput" x:Load="False" Text="@[Additional Vertical Offset:Slider:0:-500-500]" Visibility="Collapsed"></TextBlock>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<ListView
x:Name="SampleListView"
Grid.Column="0"
Margin="12"
ItemTemplate="{StaticResource NormalTemplate}"
IsItemClickEnabled="True"
Expand All @@ -37,5 +36,36 @@
ui:ListViewExtensions.AlternateItemTemplate="{StaticResource AlternateTemplate}"
ui:ListViewExtensions.ItemContainerStretchDirection="Both">
</ListView>

<StackPanel Grid.Column="1" Margin="5,0,5,0" Width="200">
<TextBox x:Name="IndexInput"
Header="Index"
InputScope="Number"
Text="0" />
<ComboBox x:Name="ItemPlacementInput"
Header="Item Placement"
SelectedIndex="0">
<x:String>Default</x:String>
<x:String>Left</x:String>
<x:String>Top</x:String>
<x:String>Center</x:String>
<x:String>Right</x:String>
<x:String>Bottom</x:String>
</ComboBox>
<CheckBox x:Name="DisableAnimationInput"
Content="Disable Animation"
IsChecked="False" />
<CheckBox x:Name="ScrollIfVisibileInput"
Content="Scroll If Visible"
IsChecked="True" />
<TextBox x:Name="AdditionalHorizontalOffsetInput"
Header="Horizontal Offset"
InputScope="Number"
Text="0" />
<TextBox x:Name="AdditionalVerticalOffsetInput"
Header="Vertical Offset"
InputScope="Number"
Text="0" />
</StackPanel>
</Grid>
</Page>

0 comments on commit 3f1b3fd

Please sign in to comment.