style<Launcher>: supports two size rules for tabs in titlebar - fixed width or size to content

This commit is contained in:
leo 2024-03-01 14:09:39 +08:00
parent e3a7abe776
commit 7b70951c93
6 changed files with 40 additions and 10 deletions

View file

@ -2,8 +2,27 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using System;
namespace SourceGit.Views {
public class LauncherTab : Grid {
public static readonly StyledProperty<bool> UseFixedTabWidthProperty =
AvaloniaProperty.Register<LauncherTab, bool>(nameof(UseFixedTabWidth), false);
public bool UseFixedTabWidth {
get => GetValue(UseFixedTabWidthProperty);
set => SetValue(UseFixedTabWidthProperty, value);
}
protected override Type StyleKeyOverride => typeof(Grid);
static LauncherTab() {
UseFixedTabWidthProperty.Changed.AddClassHandler<LauncherTab>((tab, ev) => {
tab.Width = tab.UseFixedTabWidth ? 200.0 : double.NaN;
});
}
}
public partial class Launcher : Window, Models.INotificationReceiver {
public Launcher() {
DataContext = new ViewModels.Launcher();