mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-13 04:36:36 +08:00
feat: fix dark color. add theme switch in demo. add checkbox demo.
This commit is contained in:
@@ -10,9 +10,12 @@
|
||||
d:DesignWidth="800"
|
||||
x:DataType="vm:SongsPageViewModel"
|
||||
mc:Ignorable="d">
|
||||
<TabControl>
|
||||
<TabItem Header="Songs">
|
||||
<TreeDataGrid Source="{Binding Songs}" />
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
<Button Click="Button_OnClick" Content="Theme" />
|
||||
<TabControl Grid.Row="1">
|
||||
<TabItem Header="Songs">
|
||||
<TreeDataGrid Source="{Binding Songs}" />
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Styling;
|
||||
using Semi.Avalonia.TreeDataGrid.Demo.ViewModels;
|
||||
|
||||
namespace Semi.Avalonia.TreeDataGrid.Demo;
|
||||
@@ -10,4 +13,14 @@ public partial class MainWindow : Window
|
||||
InitializeComponent();
|
||||
this.DataContext = new SongsPageViewModel();
|
||||
}
|
||||
|
||||
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var app = Application.Current;
|
||||
if (app is not null)
|
||||
{
|
||||
var theme = app.ActualThemeVariant;
|
||||
app.RequestedThemeVariant = theme == ThemeVariant.Dark ? ThemeVariant.Light : ThemeVariant.Dark;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Models.TreeDataGrid;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -9,20 +10,26 @@ namespace Semi.Avalonia.TreeDataGrid.Demo.ViewModels;
|
||||
|
||||
public class SongsPageViewModel: ObservableObject
|
||||
{
|
||||
private readonly ObservableCollection<Song> _songs;
|
||||
private readonly ObservableCollection<SongViewModel> _songs;
|
||||
|
||||
public FlatTreeDataGridSource<Song> Songs { get; }
|
||||
public FlatTreeDataGridSource<SongViewModel> Songs { get; }
|
||||
|
||||
public SongsPageViewModel()
|
||||
{
|
||||
_songs = new ObservableCollection<Song>(Song.Songs);
|
||||
_songs = new ObservableCollection<SongViewModel>(Song.Songs.Select(a => new SongViewModel()
|
||||
{
|
||||
Title = a.Title, Artist = a.Artist, Album = a.Album, CountOfComment = a.CountOfComment,
|
||||
IsSelected = false
|
||||
}));
|
||||
|
||||
Songs = new FlatTreeDataGridSource<Song>(_songs)
|
||||
Songs = new FlatTreeDataGridSource<SongViewModel>(_songs)
|
||||
{
|
||||
Columns =
|
||||
{
|
||||
new TextColumn<Song,string>("Title", a=>a.Title, (o, a) => o.Title = a, new GridLength(6, GridUnitType.Star)),
|
||||
new TextColumn<Song,string>("Artist", a=>a.Artist, (o, a) => o.Artist = a, new GridLength(6, GridUnitType.Star)),
|
||||
new CheckBoxColumn<SongViewModel>("IsSelected", a=>a.IsSelected, (model, b) => { model.IsSelected = b; }, new GridLength(72, GridUnitType.Pixel)),
|
||||
new TextColumn<SongViewModel,string>("Title", a=>a.Title, (o, a) => o.Title = a, new GridLength(6, GridUnitType.Star)),
|
||||
new TextColumn<SongViewModel,string>("Artist", a=>a.Artist, (o, a) => o.Artist = a, new GridLength(6, GridUnitType.Star)),
|
||||
new TextColumn<SongViewModel,string>("Album", a=>a.Album, (o, a) => o.Album = a, new GridLength(6, GridUnitType.Star)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user