ListBoxPage.xaml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <UserControl xmlns="https://github.com/avaloniaui"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:viewModels="using:ControlCatalog.ViewModels"
  4. x:Class="ControlCatalog.Pages.ListBoxPage"
  5. x:DataType="viewModels:ListBoxPageViewModel">
  6. <DockPanel>
  7. <DockPanel.Styles>
  8. <Style Selector="ListBox ListBoxItem:nth-child(5n+3)">
  9. <Setter Property="Foreground" Value="Red" />
  10. <Setter Property="FontWeight" Value="Bold" />
  11. </Style>
  12. <Style Selector="ListBox ListBoxItem:nth-last-child(5n+4)">
  13. <Setter Property="Background" Value="Blue" />
  14. <Setter Property="FontWeight" Value="Bold" />
  15. </Style>
  16. </DockPanel.Styles>
  17. <StackPanel DockPanel.Dock="Top" Margin="4">
  18. <TextBlock Classes="h2">Hosts a collection of ListBoxItem.</TextBlock>
  19. <TextBlock Classes="h2">Each 5th item is highlighted with nth-child(5n+3) and nth-last-child(5n+4) rules.</TextBlock>
  20. </StackPanel>
  21. <StackPanel DockPanel.Dock="Right" Margin="4">
  22. <CheckBox IsChecked="{Binding Multiple}">Multiple</CheckBox>
  23. <CheckBox IsChecked="{Binding Toggle}">Toggle</CheckBox>
  24. <CheckBox IsChecked="{Binding AlwaysSelected}">AlwaysSelected</CheckBox>
  25. <CheckBox IsChecked="{Binding AutoScrollToSelectedItem}">AutoScrollToSelectedItem</CheckBox>
  26. <CheckBox IsChecked="{Binding WrapSelection}">WrapSelection</CheckBox>
  27. </StackPanel>
  28. <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="4">
  29. <Button Command="{Binding AddItemCommand}">Add</Button>
  30. <Button Command="{Binding RemoveItemCommand}">Remove</Button>
  31. <Button Command="{Binding SelectRandomItemCommand}">Select Random Item</Button>
  32. </StackPanel>
  33. <ListBox ItemsSource="{Binding Items}"
  34. Selection="{Binding Selection}"
  35. DisplayMemberBinding="{Binding (viewModels:ItemModel).ID, StringFormat='{}Item {0:N0}'}"
  36. AutoScrollToSelectedItem="{Binding AutoScrollToSelectedItem}"
  37. SelectionMode="{Binding SelectionMode^}"
  38. WrapSelection="{Binding WrapSelection}"/>
  39. </DockPanel>
  40. </UserControl>