feat: fix dark color. add theme switch in demo. add checkbox demo.
This commit is contained in:
parent
4b2f390fa3
commit
591c728d69
@ -10,9 +10,12 @@
|
|||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
x:DataType="vm:SongsPageViewModel"
|
x:DataType="vm:SongsPageViewModel"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<TabControl>
|
<Grid RowDefinitions="Auto, *">
|
||||||
<TabItem Header="Songs">
|
<Button Click="Button_OnClick" Content="Theme" />
|
||||||
<TreeDataGrid Source="{Binding Songs}" />
|
<TabControl Grid.Row="1">
|
||||||
</TabItem>
|
<TabItem Header="Songs">
|
||||||
</TabControl>
|
<TreeDataGrid Source="{Binding Songs}" />
|
||||||
|
</TabItem>
|
||||||
|
</TabControl>
|
||||||
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Styling;
|
||||||
using Semi.Avalonia.TreeDataGrid.Demo.ViewModels;
|
using Semi.Avalonia.TreeDataGrid.Demo.ViewModels;
|
||||||
|
|
||||||
namespace Semi.Avalonia.TreeDataGrid.Demo;
|
namespace Semi.Avalonia.TreeDataGrid.Demo;
|
||||||
@ -10,4 +13,14 @@ public partial class MainWindow : Window
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.DataContext = new SongsPageViewModel();
|
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Models.TreeDataGrid;
|
using Avalonia.Controls.Models.TreeDataGrid;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
@ -9,20 +10,26 @@ namespace Semi.Avalonia.TreeDataGrid.Demo.ViewModels;
|
|||||||
|
|
||||||
public class SongsPageViewModel: ObservableObject
|
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()
|
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 =
|
Columns =
|
||||||
{
|
{
|
||||||
new TextColumn<Song,string>("Title", a=>a.Title, (o, a) => o.Title = 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<Song,string>("Artist", a=>a.Artist, (o, a) => o.Artist = a, new GridLength(6, GridUnitType.Star)),
|
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)),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
<!-- Add Resources Here -->
|
<!-- Add Resources Here -->
|
||||||
<SolidColorBrush x:Key="TreeDataGridGridLinesBrush" Opacity="0.08" Color="#1C1F23" />
|
<SolidColorBrush x:Key="TreeDataGridGridLinesBrush" Opacity="0.08" Color="White" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridHeaderPointerOverBackground" Opacity="0.09" Color="#2E3238" />
|
<SolidColorBrush x:Key="TreeDataGridHeaderPointerOverBackground" Opacity="0.16" Color="White" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridHeaderPressedBackground" Opacity="0.13" Color="#2E3238" />
|
<SolidColorBrush x:Key="TreeDataGridHeaderPressedBackground" Opacity="0.20" Color="White" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridHeaderPointerOverBorderBrush" Color="Transparent" />
|
<SolidColorBrush x:Key="TreeDataGridHeaderPointerOverBorderBrush" Color="Transparent" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridHeaderPressedBorderBrush" Color="Transparent" />
|
<SolidColorBrush x:Key="TreeDataGridHeaderPressedBorderBrush" Color="Transparent" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridHeaderPointerOverForeground" Opacity="0.8" Color="#1C1F23" />
|
<SolidColorBrush x:Key="TreeDataGridHeaderPointerOverForeground" Opacity="0.8" Color="#F9F9F9" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridHeaderPressedForeground" Opacity="1" Color="#1C1F23" />
|
<SolidColorBrush x:Key="TreeDataGridHeaderPressedForeground" Opacity="1" Color="#F9F9F9" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridCellSelectedBackground" Color="#EAF5FF" />
|
<SolidColorBrush x:Key="TreeDataGridCellSelectedBackground" Opacity="0.2" Color="#FF54A9FF" />
|
||||||
<SolidColorBrush x:Key="TreeDataGridColumnHeaderForeground" Opacity="0.62" Color="#1C1F23" />
|
<SolidColorBrush x:Key="TreeDataGridColumnHeaderForeground" Opacity="0.6" Color="#F9F9F9" />
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
|
@ -181,6 +181,8 @@
|
|||||||
BorderThickness="{TemplateBinding BorderThickness}"
|
BorderThickness="{TemplateBinding BorderThickness}"
|
||||||
CornerRadius="{TemplateBinding CornerRadius}">
|
CornerRadius="{TemplateBinding CornerRadius}">
|
||||||
<CheckBox
|
<CheckBox
|
||||||
|
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||||
|
VerticalAlignment="Center"
|
||||||
IsChecked="{TemplateBinding Value,
|
IsChecked="{TemplateBinding Value,
|
||||||
Mode=TwoWay}"
|
Mode=TwoWay}"
|
||||||
IsEnabled="{Binding !IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
|
IsEnabled="{Binding !IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user