feat: add new autocomplete box.

This commit is contained in:
rabbitism
2024-08-10 22:58:52 +08:00
parent 1a99b92eee
commit b58c8f071e
6 changed files with 184 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<UserControl 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"
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
xmlns:u="https://irihi.tech/ursa"
x:DataType="viewModels:AutoCompleteBoxDemoViewModel"
mc:Ignorable="d" d:DesignWidth="800"
d:DesignHeight="450"
x:Class="Ursa.Demo.Pages.AutoCompleteBoxDemo">
<StackPanel HorizontalAlignment="Left" Spacing="20">
<StackPanel.Styles>
<Style Selector="AutoCompleteBox">
<Setter Property="Width" Value="300" />
<Setter Property="ItemsSource">
<Binding Path="States" />
</Setter>
<Setter Property="ItemTemplate">
<DataTemplate DataType="viewModels:StateData">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</Setter>
</Style>
</StackPanel.Styles>
<u:AutoCompleteBox
Watermark="Please select a State"
ValueMemberBinding="{ReflectionBinding Name}" />
<u:AutoCompleteBox
Classes="Large"
ValueMemberBinding="{ReflectionBinding Name}" />
<u:AutoCompleteBox
Classes="Small"
ValueMemberBinding="{ReflectionBinding Name}" />
<u:AutoCompleteBox
Classes="Bordered"
ValueMemberBinding="{ReflectionBinding Name}" />
<u:AutoCompleteBox
IsEnabled="False"
Watermark="Disabled"
ValueMemberBinding="{ReflectionBinding Name}" />
<u:AutoCompleteBox
InnerLeftContent="https://"
InnerRightContent=".com"
ValueMemberBinding="{ReflectionBinding Name}" />
</StackPanel>
</UserControl>

View File

@@ -0,0 +1,13 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Ursa.Demo.Pages;
public partial class AutoCompleteBoxDemo : UserControl
{
public AutoCompleteBoxDemo()
{
InitializeComponent();
}
}

View File

@@ -0,0 +1,86 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
namespace Ursa.Demo.ViewModels;
public class AutoCompleteBoxDemoViewModel : ObservableObject
{
public AutoCompleteBoxDemoViewModel()
{
States = new ObservableCollection<StateData>(GetStates());
}
public ObservableCollection<StateData> States { get; set; }
private static List<StateData> GetStates()
{
return new List<StateData>
{
new("Alabama", "AL", "Montgomery"),
new("Alaska", "AK", "Juneau"),
new("Arizona", "AZ", "Phoenix"),
new("Arkansas", "AR", "Little Rock"),
new("California", "CA", "Sacramento"),
new("Colorado", "CO", "Denver"),
new("Connecticut", "CT", "Hartford"),
new("Delaware", "DE", "Dover"),
new("Florida", "FL", "Tallahassee"),
new("Georgia", "GA", "Atlanta"),
new("Hawaii", "HI", "Honolulu"),
new("Idaho", "ID", "Boise"),
new("Illinois", "IL", "Springfield"),
new("Indiana", "IN", "Indianapolis"),
new("Iowa", "IA", "Des Moines"),
new("Kansas", "KS", "Topeka"),
new("Kentucky", "KY", "Frankfort"),
new("Louisiana", "LA", "Baton Rouge"),
new("Maine", "ME", "Augusta"),
new("Maryland", "MD", "Annapolis"),
new("Massachusetts", "MA", "Boston"),
new("Michigan", "MI", "Lansing"),
new("Minnesota", "MN", "St. Paul"),
new("Mississippi", "MS", "Jackson"),
new("Missouri", "MO", "Jefferson City"),
new("Montana", "MT", "Helena"),
new("Nebraska", "NE", "Lincoln"),
new("Nevada", "NV", "Carson City"),
new("New Hampshire", "NH", "Concord"),
new("New Jersey", "NJ", "Trenton"),
new("New Mexico", "NM", "Santa Fe"),
new("New York", "NY", "Albany"),
new("North Carolina", "NC", "Raleigh"),
new("North Dakota", "ND", "Bismarck"),
new("Ohio", "OH", "Columbus"),
new("Oklahoma", "OK", "Oklahoma City"),
new("Oregon", "OR", "Salem"),
new("Pennsylvania", "PA", "Harrisburg"),
new("Rhode Island", "RI", "Providence"),
new("South Carolina", "SC", "Columbia"),
new("South Dakota", "SD", "Pierre"),
new("Tennessee", "TN", "Nashville"),
new("Texas", "TX", "Austin"),
new("Utah", "UT", "Salt Lake City"),
new("Vermont", "VT", "Montpelier"),
new("Virginia", "VA", "Richmond"),
new("Washington", "WA", "Olympia"),
new("West Virginia", "WV", "Charleston"),
new("Wisconsin", "WI", "Madison"),
new("Wyoming", "WY", "Cheyenne")
};
}
}
public class StateData
{
public StateData(string name, string abbreviation, string capital)
{
Name = name;
Abbreviation = abbreviation;
Capital = capital;
}
public string Name { get; private set; }
public string Abbreviation { get; private set; }
public string Capital { get; private set; }
}

View File

@@ -1,4 +1,5 @@
using System;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.Messaging;
namespace Ursa.Demo.ViewModels;
@@ -26,6 +27,7 @@ public class MainViewViewModel : ViewModelBase
Content = s switch
{
MenuKeys.MenuKeyIntroduction => new IntroductionDemoViewModel(),
MenuKeys.MenuKeyAutoCompleteBox => new AutoCompleteBoxDemoViewModel(),
MenuKeys.MenuKeyAvatar => new AvatarDemoViewModel(),
MenuKeys.MenuKeyBadge => new BadgeDemoViewModel(),
MenuKeys.MenuKeyBanner => new BannerDemoViewModel(),

View File

@@ -12,6 +12,7 @@ public class MenuViewModel: ViewModelBase
{
new() { MenuHeader = "Introduction", Key = MenuKeys.MenuKeyIntroduction, IsSeparator = false },
new() { MenuHeader = "Controls", IsSeparator = true },
new() { MenuHeader = "AutoCompleteBox", Key = MenuKeys.MenuKeyAutoCompleteBox, Status = "WIP" },
new() { MenuHeader = "Avatar", Key = MenuKeys.MenuKeyAvatar, Status = "WIP"},
new() { MenuHeader = "Badge", Key = MenuKeys.MenuKeyBadge },
new() { MenuHeader = "Banner", Key = MenuKeys.MenuKeyBanner },
@@ -61,6 +62,7 @@ public class MenuViewModel: ViewModelBase
public static class MenuKeys
{
public const string MenuKeyIntroduction = "Introduction";
public const string MenuKeyAutoCompleteBox = "AutoCompleteBox";
public const string MenuKeyAvatar = "Avatar";
public const string MenuKeyBadge = "Badge";
public const string MenuKeyBanner = "Banner";