feat: Add HoneycombPanel and demo.
This commit is contained in:
1 parent
d1944b01c3
commit
e7005d09b5
16 files changed
+263
-1
No files matched your search
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<!--If you are willing to use Windows/MacOS native APIs you will need to create 3 projects.
|
||||
@@ -19,12 +19,14 @@
|
||||
<None Remove="Data\DemoInfo.json" />
|
||||
<None Remove="Resources\Img\cloud.png" />
|
||||
<None Remove="Resources\Img\icon.ico" />
|
||||
<None Remove="Resources\Img\Avatar\*.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Data\DemoInfo.json" />
|
||||
<AvaloniaResource Include="Resources\Img\cloud.png" />
|
||||
<AvaloniaResource Include="Resources\Img\icon.ico" />
|
||||
<AvaloniaResource Include="Resources\Img\Avatar\*.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 693 B |
Binary file not shown.
|
After Width: | Height: | Size: 966 B |
Binary file not shown.
|
After Width: | Height: | Size: 878 B |
Binary file not shown.
|
After Width: | Height: | Size: 927 B |
Binary file not shown.
|
After Width: | Height: | Size: 995 B |
Binary file not shown.
|
After Width: | Height: | Size: 726 B |
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,40 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:vm="clr-namespace:HandyControlDemo.ViewModel"
|
||||
x:Class="HandyControlDemo.UserControl.HoneycombPanelDemo"
|
||||
DataContext="{Binding HoneycombPanelDemo, Source={x:Static vm:ViewModelLocator.Instance}}">
|
||||
<Grid Margin="32">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Orientation="Horizontal"
|
||||
Spacing="8"
|
||||
Margin="0,0,0,16">
|
||||
<Button Command="{Binding AddItemCommand}" Content="Add" />
|
||||
<Button Command="{Binding RemoveItemCommand}" Content="Remove" />
|
||||
</StackPanel>
|
||||
<ItemsControl Grid.Row="1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
ItemsSource="{Binding DataList}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<hc:HoneycombPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Border Width="60"
|
||||
Height="60"
|
||||
Margin="6"
|
||||
CornerRadius="30"
|
||||
ClipToBounds="True">
|
||||
<Image Source="{Binding}" Stretch="UniformToFill" />
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class HoneycombPanelDemo : Avalonia.Controls.UserControl
|
||||
{
|
||||
public HoneycombPanelDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
+42
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Avalonia.Platform;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace HandyControlDemo.ViewModel;
|
||||
|
||||
public partial class HoneycombPanelDemoViewModel : ObservableObject
|
||||
{
|
||||
private static readonly Random Random = new();
|
||||
|
||||
[ObservableProperty] private ObservableCollection<Bitmap> _dataList = [];
|
||||
|
||||
public HoneycombPanelDemoViewModel()
|
||||
{
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
DataList.Add(LoadRandomAvatar());
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void AddItem() => DataList.Insert(0, LoadRandomAvatar());
|
||||
|
||||
[RelayCommand]
|
||||
private void RemoveItem()
|
||||
{
|
||||
if (DataList.Count > 0)
|
||||
{
|
||||
DataList.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap LoadRandomAvatar()
|
||||
{
|
||||
var uri = new Uri($"avares://HandyControlDemo/Resources/Img/Avatar/avatar{Random.Next(1, 7)}.png");
|
||||
using var stream = AssetLoader.Open(uri);
|
||||
return new Bitmap(stream);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ public class ViewModelLocator
|
||||
services.AddSingleton<DataService>();
|
||||
services.AddTransient<MainViewModel>();
|
||||
services.AddTransient<InputElementDemoViewModel>();
|
||||
services.AddTransient<HoneycombPanelDemoViewModel>();
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
}
|
||||
@@ -27,4 +28,6 @@ public class ViewModelLocator
|
||||
public MainViewModel Main => _serviceProvider.GetService<MainViewModel>()!;
|
||||
|
||||
public InputElementDemoViewModel InputElementDemo => _serviceProvider.GetService<InputElementDemoViewModel>()!;
|
||||
|
||||
public HoneycombPanelDemoViewModel HoneycombPanelDemo => _serviceProvider.GetService<HoneycombPanelDemoViewModel>()!;
|
||||
}
|
||||
Reference in new issue
Block a user