From 3f1b3fdd2278e5f538381cfa290e7309b6750d8d Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Mon, 28 Jun 2021 12:20:05 -0400 Subject: [PATCH] Make scrool controls part of the sample --- .../ListViewExtensionsPage.xaml | 36 ++++++++++++++++ .../ListViewExtensionsPage.xaml.cs | 40 +++++++++++------- .../ListViewExtensionsXaml.bind | 42 ++++++++++++++++--- 3 files changed, 97 insertions(+), 21 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml index 7107a732929..4e81fb93152 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml @@ -20,7 +20,12 @@ + + + + + + + + + Default + Left + Top + Center + Right + Bottom + + + + + + \ No newline at end of file diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml.cs index 1d8e4d5a388..4eef27f345c 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsPage.xaml.cs @@ -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. @@ -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() { @@ -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) { @@ -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); }); diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsXaml.bind index a305b62926b..b323642055a 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ListViewExtensions/ListViewExtensionsXaml.bind @@ -20,15 +20,14 @@ - - - - - - + + + + + + + + + Default + Left + Top + Center + Right + Bottom + + + + + + \ No newline at end of file