feat: add listbox item.
This commit is contained in:
parent
b32aee2e40
commit
8a1697ae29
@ -41,5 +41,8 @@
|
||||
<TabItem Header="RepeatButton">
|
||||
<pages:RepeatButtonDemo />
|
||||
</TabItem>
|
||||
<TabItem Header="ListBox">
|
||||
<pages:ListBoxItem />
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Window>
|
||||
|
21
src/Semi.Avalonia.Demo/Pages/ListBoxItem.axaml
Normal file
21
src/Semi.Avalonia.Demo/Pages/ListBoxItem.axaml
Normal file
@ -0,0 +1,21 @@
|
||||
<UserControl
|
||||
x:Class="Semi.Avalonia.Demo.Pages.ListBoxItem" xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="450"
|
||||
d:DesignWidth="800" mc:Ignorable="d">
|
||||
<ListBox Margin="20">
|
||||
<ListBoxItem>Item 1</ListBoxItem>
|
||||
<ListBoxItem>Item 2</ListBoxItem>
|
||||
<ListBoxItem IsEnabled="False">Item 3</ListBoxItem>
|
||||
<ListBoxItem>Item 4</ListBoxItem>
|
||||
<ListBoxItem>Item 5</ListBoxItem>
|
||||
<ListBoxItem>Item 6</ListBoxItem>
|
||||
<ListBoxItem>Item 7</ListBoxItem>
|
||||
<ListBoxItem IsEnabled="False">Item 8</ListBoxItem>
|
||||
<ListBoxItem>Item 9</ListBoxItem>
|
||||
<ListBoxItem>Item 10</ListBoxItem>
|
||||
<ListBoxItem>Item 11</ListBoxItem>
|
||||
<ListBoxItem>Item 12</ListBoxItem>
|
||||
<ListBoxItem>Item 13</ListBoxItem>
|
||||
</ListBox>
|
||||
</UserControl>
|
18
src/Semi.Avalonia.Demo/Pages/ListBoxItem.axaml.cs
Normal file
18
src/Semi.Avalonia.Demo/Pages/ListBoxItem.axaml.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Semi.Avalonia.Demo.Pages;
|
||||
|
||||
public partial class ListBoxItem : UserControl
|
||||
{
|
||||
public ListBoxItem()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Controls/CheckBox.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Controls/Expander.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Controls/Label.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Controls/ListBox.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Controls/PathIcon.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Controls/RadioButton.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Controls/RepeatButton.axaml" />
|
||||
|
88
src/Semi.Avalonia/Controls/ListBox.axaml
Normal file
88
src/Semi.Avalonia/Controls/ListBox.axaml
Normal file
@ -0,0 +1,88 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Design.PreviewWith>
|
||||
<ListBox Margin="30">
|
||||
<ListBoxItem>Item 1</ListBoxItem>
|
||||
<ListBoxItem>Item 2</ListBoxItem>
|
||||
<ListBoxItem>Item 3</ListBoxItem>
|
||||
<ListBoxItem IsEnabled="False" IsSelected="True">Item 3</ListBoxItem>
|
||||
<ListBoxItem>Item 4</ListBoxItem>
|
||||
</ListBox>
|
||||
</Design.PreviewWith>
|
||||
<ControlTheme x:Key="{x:Type ListBox}" TargetType="ListBox">
|
||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
|
||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
|
||||
<Setter Property="ScrollViewer.IsScrollChainingEnabled" Value="True" />
|
||||
<Setter Property="ListBox.Template">
|
||||
<ControlTemplate TargetType="ListBox">
|
||||
<Border
|
||||
Name="border"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
ClipToBounds="{TemplateBinding ClipToBounds}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<ScrollViewer
|
||||
Name="PART_ScrollViewer"
|
||||
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}"
|
||||
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
|
||||
IsScrollChainingEnabled="{TemplateBinding (ScrollViewer.IsScrollChainingEnabled)}"
|
||||
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}">
|
||||
<ItemsPresenter
|
||||
Name="PART_ItemsPresenter"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
ItemTemplate="{TemplateBinding ItemTemplate}"
|
||||
Items="{TemplateBinding Items}"
|
||||
ItemsPanel="{TemplateBinding ItemsPanel}"
|
||||
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
|
||||
<ControlTheme x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
|
||||
<Setter Property="ListBoxItem.Background" Value="{DynamicResource ListBoxItemDefaultBackground}" />
|
||||
<Setter Property="ListBoxItem.Padding" Value="{DynamicResource ListBoxItemDefaultPadding}" />
|
||||
<Setter Property="ListBoxItem.CornerRadius" Value="{DynamicResource ListBoxItemCornerRadius}" />
|
||||
<Setter Property="ListBoxItem.Template">
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<ContentPresenter
|
||||
Name="PART_ContentPresenter"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
FontWeight="Normal"
|
||||
Foreground="{TemplateBinding Foreground}" />
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
<Style Selector="^:disabled">
|
||||
<Setter Property="ListBoxItem.Foreground" Value="{DynamicResource ListBoxItemDisabledForeground}" />
|
||||
<Setter Property="ListBoxItem.Background" Value="{DynamicResource ListBoxItemDisabledBackground}" />
|
||||
<Style Selector="^:selected">
|
||||
<Setter Property="ListBoxItem.Background" Value="{DynamicResource ListBoxItemSelectedDisabledBackground}" />
|
||||
</Style>
|
||||
</Style>
|
||||
|
||||
<!-- PointerOver State -->
|
||||
<Style Selector="^:pointerover">
|
||||
<Setter Property="ListBoxItem.Background" Value="{DynamicResource ListBoxItemPointerOverBackground}" />
|
||||
</Style>
|
||||
|
||||
<!-- Pressed State -->
|
||||
<Style Selector="^:pressed">
|
||||
<Setter Property="ListBoxItem.Background" Value="{DynamicResource ListBoxItemPressedBackground}" />
|
||||
</Style>
|
||||
|
||||
<!-- Selected State -->
|
||||
<Style Selector="^:selected">
|
||||
<Setter Property="ListBoxItem.Background" Value="{DynamicResource ListBoxItemSelectedBackground}" />
|
||||
</Style>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
@ -7,6 +7,7 @@
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/CheckBox.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/Expander.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/Label.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/ListBox.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/RadioButton.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/ScrollViewer.axaml" />
|
||||
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/TabControl.axaml" />
|
||||
|
19
src/Semi.Avalonia/Themes/Light/ListBox.axaml
Normal file
19
src/Semi.Avalonia/Themes/Light/ListBox.axaml
Normal file
@ -0,0 +1,19 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<Thickness x:Key="ListBoxItemDefaultPadding">8 4</Thickness>
|
||||
|
||||
<SolidColorBrush x:Key="ListBoxItemDefaultForeground" Color="#1C1F23" />
|
||||
<SolidColorBrush x:Key="ListBoxItemIconDefaultForeground" Opacity="0.62" Color="#1C1F23" />
|
||||
<SolidColorBrush x:Key="ListBoxItemIconHoverForeground" Color="#1C1F23" />
|
||||
<SolidColorBrush x:Key="ListBoxItemDisabledForeground" Opacity="0.35" Color="#1C1F23" />
|
||||
|
||||
<SolidColorBrush x:Key="ListBoxItemDefaultBackground" Color="Transparent" />
|
||||
<SolidColorBrush x:Key="ListBoxItemPointerOverBackground" Opacity="0.05" Color="#2E3238" />
|
||||
<SolidColorBrush x:Key="ListBoxItemPressedBackground" Opacity="0.09" Color="#2E3238" />
|
||||
<SolidColorBrush x:Key="ListBoxItemSelectedBackground" Color="#EAF5FF" />
|
||||
<SolidColorBrush x:Key="ListBoxItemSelectedPointeroverBackground" Color="#CBE7FE" />
|
||||
<SolidColorBrush x:Key="ListBoxItemDisabledBackground" Color="Transparent" />
|
||||
<SolidColorBrush x:Key="ListBoxItemSelectedDisabledBackground" Opacity="0.04" Color="#2E3238" />
|
||||
<CornerRadius x:Key="ListBoxItemCornerRadius">3</CornerRadius>
|
||||
|
||||
</ResourceDictionary>
|
Loading…
x
Reference in New Issue
Block a user