csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
3.6 KiB
72 lines
3.6 KiB
<UserControl xmlns="https://github.com/avaloniaui"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:viewModels="using:ControlCatalog.ViewModels"
|
|
x:Class="ControlCatalog.Pages.ListBoxPage"
|
|
x:DataType="viewModels:ListBoxPageViewModel">
|
|
<DockPanel>
|
|
<DockPanel.Styles>
|
|
<Style Selector="ListBox ListBoxItem:nth-child(even)">
|
|
<Setter Property="ContextFlyout">
|
|
<MenuFlyout>
|
|
<MenuItem Header="Hello there" />
|
|
</MenuFlyout>
|
|
</Setter>
|
|
</Style>
|
|
<Style Selector="ListBox ListBoxItem:nth-child(5n+3)">
|
|
<Setter Property="Foreground" Value="Red" />
|
|
<Setter Property="FontWeight" Value="Bold" />
|
|
</Style>
|
|
<Style Selector="ListBox ListBoxItem:nth-last-child(5n+4)">
|
|
<Setter Property="Background" Value="Beige" />
|
|
<Setter Property="FontWeight" Value="Bold" />
|
|
</Style>
|
|
<Style Selector="VirtualizingStackPanel">
|
|
<Setter Property="CacheLength" Value="0.5" />
|
|
</Style>
|
|
</DockPanel.Styles>
|
|
<StackPanel DockPanel.Dock="Top" Margin="4">
|
|
<TextBlock Classes="h2">Hosts a collection of ListBoxItem.</TextBlock>
|
|
<TextBlock Classes="h2">Each 5th item is highlighted with nth-child(5n+3) and nth-last-child(5n+4) rules.</TextBlock>
|
|
</StackPanel>
|
|
<StackPanel DockPanel.Dock="Right" Margin="4">
|
|
<CheckBox IsChecked="{Binding Multiple}">Multiple</CheckBox>
|
|
<CheckBox IsChecked="{Binding Toggle}">Toggle</CheckBox>
|
|
<CheckBox IsChecked="{Binding AlwaysSelected}">AlwaysSelected</CheckBox>
|
|
<CheckBox IsChecked="{Binding AutoScrollToSelectedItem}">AutoScrollToSelectedItem</CheckBox>
|
|
<CheckBox IsChecked="{Binding WrapSelection}">WrapSelection</CheckBox>
|
|
<Separator/>
|
|
<TextBox Name="SearchBox" Watermark="Search for a number"/>
|
|
<CheckBox Name="InvertSort">Sort Descending</CheckBox>
|
|
<CheckBox Name="FavToTop">Sort Favorites to top</CheckBox>
|
|
</StackPanel>
|
|
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" Margin="4">
|
|
<Button Command="{Binding AddItemCommand}">Add</Button>
|
|
<Button Command="{Binding RemoveItemCommand}">Remove</Button>
|
|
<Button Command="{Binding SelectRandomItemCommand}">Select Random Item</Button>
|
|
</StackPanel>
|
|
<ListBox Name="ListBox"
|
|
ItemsSource="{Binding Items}"
|
|
Selection="{Binding Selection}"
|
|
AutoScrollToSelectedItem="{Binding AutoScrollToSelectedItem}"
|
|
SelectionMode="{Binding SelectionMode^}"
|
|
WrapSelection="{Binding WrapSelection}">
|
|
<ListBox.Filters>
|
|
<FunctionItemFilter Filter="FilterItem" State="{Binding Text, ElementName=SearchBox}" InvalidationPropertyNames="IsFavorite"/>
|
|
</ListBox.Filters>
|
|
<ListBox.Sorters>
|
|
<ComparableSorter ComparableSelector="SelectItemIsFavorite" SortDirection="Descending" IsActive="{Binding IsChecked, ElementName=FavToTop}" InvalidationPropertyNames="IsFavorite" />
|
|
<ComparableSorter ComparableSelector="SelectItemId" SortDirection="{Binding IsChecked, ElementName=InvertSort, Converter={x:Static ItemSorter.BooleanToDescendingSortConverter}}" />
|
|
</ListBox.Sorters>
|
|
<ListBox.ItemTemplate>
|
|
<DataTemplate x:DataType="viewModels:ItemModel">
|
|
<Grid ColumnDefinitions="*,Auto">
|
|
<TextBlock VerticalAlignment="Center">
|
|
Item <Run Text="{Binding ID, StringFormat=n0, Mode=OneWay}"/>
|
|
</TextBlock>
|
|
<ToggleButton Grid.Column="1" IsChecked="{Binding IsFavorite}" Content="Favorite"/>
|
|
</Grid>
|
|
</DataTemplate>
|
|
</ListBox.ItemTemplate>
|
|
</ListBox>
|
|
</DockPanel>
|
|
</UserControl>
|
|
|