chore: add avalonia ListBox demo.
This commit is contained in:
1 parent
98b67b3fd5
commit
29cf68d8ec
7 files changed
+157
-58
No files matched your search
@@ -12,6 +12,36 @@ namespace HandyControlDemo.Service;
|
||||
|
||||
public class DataService
|
||||
{
|
||||
internal List<DemoDataModel> GetDemoDataList()
|
||||
{
|
||||
var list = new List<DemoDataModel>();
|
||||
for (int i = 1; i <= 20; i++)
|
||||
{
|
||||
var dataList = new List<DemoDataModel>();
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
dataList.Add(new DemoDataModel
|
||||
{
|
||||
Index = j, IsSelected = j % 2 == 0, Name = $"SubName{j}", Type = (DemoType)j
|
||||
});
|
||||
}
|
||||
|
||||
var model = new DemoDataModel
|
||||
{
|
||||
Index = i,
|
||||
IsSelected = i % 2 == 0,
|
||||
Name = $"Name{i}",
|
||||
Type = (DemoType)(i % 6 + 1),
|
||||
DataList = dataList,
|
||||
ImgPath = $"/HandyControlDemo;component/Resources/Img/Avatar/avatar{i % 6 + 1}.png",
|
||||
Remark = new string(i.ToString()[0], 10)
|
||||
};
|
||||
list.Add(model);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
internal List<DemoInfoModel> GetDemoInfo()
|
||||
{
|
||||
var infoList = new List<DemoInfoModel>();
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="HandyControlDemo.UserControl.ListBoxDemo">
|
||||
<WrapPanel Margin="16">
|
||||
<ListBox Margin="16"
|
||||
Width="200"
|
||||
ItemsSource="{Binding DataList}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<ListBox Margin="16"
|
||||
Width="200"
|
||||
ItemsSource="{Binding DataList}"
|
||||
Theme="{StaticResource ListBox.Small}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</WrapPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class ListBoxDemo : Avalonia.Controls.UserControl
|
||||
{
|
||||
public ListBoxDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -76,11 +76,20 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
|
||||
|
||||
//load items
|
||||
DemoInfoCollection = [];
|
||||
foreach (var item in _dataService.GetDemoInfo())
|
||||
Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
Dispatcher.UIThread.InvokeAsync(() => DemoInfoCollection.Add(item));
|
||||
}
|
||||
Dispatcher.UIThread.InvokeAsync(() => SwitchDemo(DemoInfoCollection.First().DemoItemList.First()));
|
||||
DataList = _dataService.GetDemoDataList();
|
||||
|
||||
foreach (var item in _dataService.GetDemoInfo())
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}
|
||||
|
||||
if (DemoInfoCollection.Any() && DemoInfoCollection.First().DemoItemList.Any())
|
||||
{
|
||||
SwitchDemo(DemoInfoCollection.First().DemoItemList.First());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void SwitchDemo(DemoItemModel item)
|
||||
|
||||
Reference in new issue
Block a user