Browse Source
Add support for selection wrapping for ListBox, ItemsControl, ComboBox. Co-authored-by: Steven Kirk <grokys@users.noreply.github.com> Co-authored-by: Takoooooo <tako0qq@gmail.com> Co-authored-by: Steven Kirk <grokys@gmail.com>pull/7527/head
committed by
GitHub
11 changed files with 232 additions and 90 deletions
@ -1,77 +1,95 @@ |
|||||
<UserControl xmlns="https://github.com/avaloniaui" |
<UserControl |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
x:Class="ControlCatalog.Pages.ComboBoxPage" |
||||
x:Class="ControlCatalog.Pages.ComboBoxPage" |
xmlns="https://github.com/avaloniaui" |
||||
xmlns:sys="using:System" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:col="using:System.Collections"> |
xmlns:col="using:System.Collections" |
||||
<StackPanel Orientation="Vertical" Spacing="4"> |
xmlns:sys="using:System"> |
||||
<TextBlock Classes="h2">A drop-down list.</TextBlock> |
<StackPanel Orientation="Vertical" Spacing="4"> |
||||
|
<TextBlock Classes="h2">A drop-down list.</TextBlock> |
||||
|
|
||||
<WrapPanel HorizontalAlignment="Center" Margin="0 16 0 0" |
<StackPanel |
||||
MaxWidth="660"> |
Margin="0,16,0,0" |
||||
<WrapPanel.Styles> |
HorizontalAlignment="Center" |
||||
<Style Selector="ComboBox"> |
Orientation="Horizontal" |
||||
<Setter Property="Width" Value="250" /> |
Spacing="8"> |
||||
<Setter Property="Margin" Value="10" /> |
<WrapPanel |
||||
</Style> |
MaxWidth="660" |
||||
</WrapPanel.Styles> |
Margin="0,16,0,0" |
||||
<ComboBox PlaceholderText="Pick an Item"> |
HorizontalAlignment="Center"> |
||||
<ComboBoxItem>Inline Items</ComboBoxItem> |
<WrapPanel.Styles> |
||||
<ComboBoxItem>Inline Item 2</ComboBoxItem> |
<Style Selector="ComboBox"> |
||||
<ComboBoxItem>Inline Item 3</ComboBoxItem> |
<Setter Property="Width" Value="250" /> |
||||
<ComboBoxItem>Inline Item 4</ComboBoxItem> |
<Setter Property="Margin" Value="10" /> |
||||
</ComboBox> |
</Style> |
||||
|
</WrapPanel.Styles> |
||||
|
|
||||
<ComboBox> |
<ComboBox PlaceholderText="Pick an Item" WrapSelection="{Binding WrapSelection}"> |
||||
<ComboBox.Items> |
<ComboBoxItem>Inline Items</ComboBoxItem> |
||||
<col:ArrayList> |
<ComboBoxItem>Inline Item 2</ComboBoxItem> |
||||
<x:Null /> |
<ComboBoxItem>Inline Item 3</ComboBoxItem> |
||||
<sys:String>Hello</sys:String> |
<ComboBoxItem>Inline Item 4</ComboBoxItem> |
||||
<sys:String>World</sys:String> |
</ComboBox> |
||||
</col:ArrayList> |
|
||||
</ComboBox.Items> |
|
||||
<ComboBox.ItemTemplate> |
|
||||
<DataTemplate> |
|
||||
<Panel> |
|
||||
<TextBlock Text="{Binding}" /> |
|
||||
<TextBlock Text="Null object" IsVisible="{Binding Converter={x:Static ObjectConverters.IsNull}}" /> |
|
||||
</Panel> |
|
||||
</DataTemplate> |
|
||||
</ComboBox.ItemTemplate> |
|
||||
</ComboBox> |
|
||||
|
|
||||
<ComboBox SelectedIndex="0"> |
<ComboBox WrapSelection="{Binding WrapSelection}"> |
||||
<ComboBoxItem> |
<ComboBox.Items> |
||||
<Panel> |
<col:ArrayList> |
||||
<Rectangle Fill="{DynamicResource SystemAccentColor}"/> |
<x:Null /> |
||||
<TextBlock Margin="8">Control Items</TextBlock> |
<sys:String>Hello</sys:String> |
||||
</Panel> |
<sys:String>World</sys:String> |
||||
</ComboBoxItem> |
</col:ArrayList> |
||||
<ComboBoxItem> |
</ComboBox.Items> |
||||
<Ellipse Width="50" Height="50" Fill="Yellow"/> |
<ComboBox.ItemTemplate> |
||||
</ComboBoxItem> |
<DataTemplate> |
||||
<ComboBoxItem> |
<Panel> |
||||
<TextBox Text="TextBox"/> |
<TextBlock Text="{Binding}" /> |
||||
</ComboBoxItem> |
<TextBlock IsVisible="{Binding Converter={x:Static ObjectConverters.IsNull}}" Text="Null object" /> |
||||
</ComboBox> |
</Panel> |
||||
|
</DataTemplate> |
||||
|
</ComboBox.ItemTemplate> |
||||
|
</ComboBox> |
||||
|
|
||||
<ComboBox x:Name="fontComboBox" SelectedIndex="0"> |
<ComboBox SelectedIndex="0" WrapSelection="{Binding WrapSelection}"> |
||||
<ComboBox.ItemTemplate> |
<ComboBoxItem> |
||||
<DataTemplate> |
<Panel> |
||||
<TextBlock Text="{Binding Name}" FontFamily="{Binding}" /> |
<Rectangle Fill="{DynamicResource SystemAccentColor}" /> |
||||
</DataTemplate> |
<TextBlock Margin="8">Control Items</TextBlock> |
||||
</ComboBox.ItemTemplate> |
</Panel> |
||||
</ComboBox> |
</ComboBoxItem> |
||||
|
<ComboBoxItem> |
||||
<ComboBox PlaceholderText="Pick an Item"> |
<Ellipse |
||||
<ComboBoxItem>Inline Items</ComboBoxItem> |
Width="50" |
||||
<ComboBoxItem>Inline Item 2</ComboBoxItem> |
Height="50" |
||||
<ComboBoxItem>Inline Item 3</ComboBoxItem> |
Fill="Yellow" /> |
||||
<ComboBoxItem>Inline Item 4</ComboBoxItem> |
</ComboBoxItem> |
||||
<DataValidationErrors.Error> |
<ComboBoxItem> |
||||
<sys:Exception /> |
<TextBox Text="TextBox" /> |
||||
</DataValidationErrors.Error> |
</ComboBoxItem> |
||||
</ComboBox> |
</ComboBox> |
||||
</WrapPanel> |
|
||||
|
|
||||
</StackPanel> |
<ComboBox |
||||
|
x:Name="fontComboBox" |
||||
|
SelectedIndex="0" |
||||
|
WrapSelection="{Binding WrapSelection}"> |
||||
|
<ComboBox.ItemTemplate> |
||||
|
<DataTemplate> |
||||
|
<TextBlock FontFamily="{Binding}" Text="{Binding Name}" /> |
||||
|
</DataTemplate> |
||||
|
</ComboBox.ItemTemplate> |
||||
|
</ComboBox> |
||||
|
|
||||
|
<ComboBox PlaceholderText="Pick an Item" WrapSelection="{Binding WrapSelection}"> |
||||
|
<ComboBoxItem>Inline Items</ComboBoxItem> |
||||
|
<ComboBoxItem>Inline Item 2</ComboBoxItem> |
||||
|
<ComboBoxItem>Inline Item 3</ComboBoxItem> |
||||
|
<ComboBoxItem>Inline Item 4</ComboBoxItem> |
||||
|
<DataValidationErrors.Error> |
||||
|
<sys:Exception /> |
||||
|
</DataValidationErrors.Error> |
||||
|
</ComboBox> |
||||
|
</WrapPanel> |
||||
|
|
||||
|
<CheckBox IsChecked="{Binding WrapSelection}">WrapSelection</CheckBox> |
||||
|
|
||||
|
</StackPanel> |
||||
|
</StackPanel> |
||||
</UserControl> |
</UserControl> |
||||
|
|||||
@ -0,0 +1,21 @@ |
|||||
|
using System; |
||||
|
using System.Collections.ObjectModel; |
||||
|
using System.Linq; |
||||
|
using System.Reactive; |
||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.Controls.Selection; |
||||
|
using MiniMvvm; |
||||
|
|
||||
|
namespace ControlCatalog.ViewModels |
||||
|
{ |
||||
|
public class ComboBoxPageViewModel : ViewModelBase |
||||
|
{ |
||||
|
private bool _wrapSelection; |
||||
|
|
||||
|
public bool WrapSelection |
||||
|
{ |
||||
|
get => _wrapSelection; |
||||
|
set => this.RaiseAndSetIfChanged(ref _wrapSelection, value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue