Skip to content

Commit

Permalink
test: adjust the ListView.ScrollIntoView sample to use items with var…
Browse files Browse the repository at this point in the history
…ying heights
  • Loading branch information
ramezgerges committed Apr 11, 2024
1 parent 2002cc0 commit cbf30bd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
</StackPanel>
</DataTemplate>
</UserControl.Resources>

<Grid>
<ListView x:Name="myList"
ItemsSource="{Binding [SampleItemsMed]}"
ItemTemplate="{StaticResource ListItemTemplate}"/>
<Button Content="Bring into view"
Click="BringIntoView" />
</Grid>

<StackPanel>
<StackPanel Orientation="Horizontal">
<NumberBox x:Name="nb" Minimum="0" SmallChange="1" />
<StackPanel>
<TextBlock Text="Leading" />
<CheckBox x:Name="chkBox" />
</StackPanel>
<Button Content="Bring into view" Click="BringIntoView" />
</StackPanel>
<Grid Height="400">
<ListView x:Name="myList" ItemTemplate="{StaticResource ListItemTemplate}" />
</Grid>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Uno.UI.Samples.Controls;
using System;
using System.Linq;
using Uno.UI.Samples.Controls;
using Microsoft.UI.Xaml.Controls;
using SamplesApp.Windows_UI_Xaml_Controls.Models;
using Microsoft.UI.Xaml;
Expand All @@ -14,13 +16,18 @@ public sealed partial class ListView_BringIntoView : UserControl
public ListView_BringIntoView()
{
this.InitializeComponent();

var random = new Random(42);
// using newlines to vary the height of each item
myList.ItemsSource = Enumerable.Range(0, 100).Select(i => $"item {i}" + new string('\n', random.Next(0, 5))).ToArray();
}

public void BringIntoView(object sender, RoutedEventArgs e)
{
var list = (Microsoft.UI.Xaml.Controls.ListViewBase)this.myList;

list.ScrollIntoView(list.SelectedItem, ScrollIntoViewAlignment.Leading);
var alignment = (chkBox.IsChecked ?? false) ? ScrollIntoViewAlignment.Leading : ScrollIntoViewAlignment.Default;
list.ScrollIntoView(list.ItemFromIndex((int)nb.Value), alignment);
}
}
}

0 comments on commit cbf30bd

Please sign in to comment.