ItemsRepeaterPage.xaml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <UserControl xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. x:Class="ControlCatalog.Pages.ItemsRepeaterPage">
  4. <UserControl.Resources>
  5. <RecyclePool x:Key="RecyclePool" />
  6. <DataTemplate x:Key="odd">
  7. <TextBlock Background="Yellow"
  8. Foreground="Black"
  9. Height="{Binding Height}"
  10. Text="{Binding Text}"/>
  11. </DataTemplate>
  12. <DataTemplate x:Key="even">
  13. <TextBlock Background="Wheat"
  14. Foreground="Black"
  15. Height="{Binding Height}"
  16. Text="{Binding Text}"/>
  17. </DataTemplate>
  18. <RecyclingElementFactory x:Key="elementFactory"
  19. RecyclePool="{StaticResource RecyclePool}"
  20. SelectTemplateKey="OnSelectTemplateKey">
  21. <RecyclingElementFactory.Templates>
  22. <StaticResource x:Key="odd" ResourceKey="odd" />
  23. <StaticResource x:Key="even" ResourceKey="even" />
  24. </RecyclingElementFactory.Templates>
  25. </RecyclingElementFactory>
  26. </UserControl.Resources>
  27. <DockPanel>
  28. <StackPanel DockPanel.Dock="Top" Spacing="4" Margin="0 0 0 16">
  29. <TextBlock Classes="h1">ItemsRepeater</TextBlock>
  30. <TextBlock Classes="h2">A data-driven collection control that incorporates a flexible layout system, custom views, and virtualization.</TextBlock>
  31. </StackPanel>
  32. <StackPanel DockPanel.Dock="Right" Margin="8 0" Spacing="4">
  33. <ComboBox SelectedIndex="0" SelectionChanged="LayoutChanged">
  34. <ComboBoxItem>Stack - Vertical</ComboBoxItem>
  35. <ComboBoxItem>Stack - Horizontal</ComboBoxItem>
  36. <ComboBoxItem>UniformGrid - Vertical</ComboBoxItem>
  37. <ComboBoxItem>UniformGrid - Horizontal</ComboBoxItem>
  38. </ComboBox>
  39. <Button Command="{Binding AddItem}">Add Item</Button>
  40. <Button Command="{Binding RandomizeHeights}">Randomize Heights</Button>
  41. <Button Command="{Binding ResetItems}">Reset items</Button>
  42. <Button x:Name="scrollToLast">Scroll to Last</Button>
  43. <Button x:Name="scrollToRandom">Scroll to Random</Button>
  44. </StackPanel>
  45. <Border BorderThickness="1" BorderBrush="{DynamicResource SystemControlHighlightBaseMediumLowBrush}" Margin="0 0 0 16">
  46. <ScrollViewer Name="scroller"
  47. HorizontalScrollBarVisibility="Auto"
  48. VerticalScrollBarVisibility="Auto">
  49. <ItemsRepeater Name="repeater" Background="Transparent" Items="{Binding Items}"
  50. ItemTemplate="{StaticResource elementFactory}"/>
  51. </ScrollViewer>
  52. </Border>
  53. </DockPanel>
  54. </UserControl>