mirror of
https://github.com/jackqqq123/luban_ui_internal.git
synced 2025-11-15 13:48:24 +08:00
133 lines
4.2 KiB
C#
133 lines
4.2 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Controls.Selection;
|
|
using LubanHub.App.Services;
|
|
|
|
namespace LubanHub.App;
|
|
|
|
public partial class MainWindow : Window
|
|
{
|
|
private Panel? _contentPanel;
|
|
private StackPanel? _welcomePanel;
|
|
private Grid? _knowledgePanel;
|
|
private Grid? _projectPanel;
|
|
private Grid? _installPanel;
|
|
private Grid? _settingsPanel;
|
|
|
|
private Button? _knowledgeButton;
|
|
private Button? _projectButton;
|
|
private Button? _installButton;
|
|
private Button? _settingsButton;
|
|
private ComboBox? _themeComboBox;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponents();
|
|
|
|
// 订阅主题变化事件
|
|
ThemeManager.ThemeChanged += OnThemeChanged;
|
|
|
|
// 初始化主题
|
|
ThemeManager.Initialize();
|
|
UpdateThemeComboBox();
|
|
}
|
|
|
|
private void InitializeComponents()
|
|
{
|
|
// 获取面板引用
|
|
_contentPanel = this.FindControl<Panel>("ContentPanel");
|
|
_welcomePanel = this.FindControl<StackPanel>("WelcomePanel");
|
|
_knowledgePanel = this.FindControl<Grid>("KnowledgePanel");
|
|
_projectPanel = this.FindControl<Grid>("ProjectPanel");
|
|
_installPanel = this.FindControl<Grid>("InstallPanel");
|
|
_settingsPanel = this.FindControl<Grid>("SettingsPanel");
|
|
|
|
// 获取按钮引用
|
|
_knowledgeButton = this.FindControl<Button>("KnowledgeButton");
|
|
_projectButton = this.FindControl<Button>("ProjectButton");
|
|
_installButton = this.FindControl<Button>("InstallButton");
|
|
_settingsButton = this.FindControl<Button>("SettingsButton");
|
|
_themeComboBox = this.FindControl<ComboBox>("ThemeComboBox");
|
|
}
|
|
|
|
private void ShowPanel(Grid? targetPanel)
|
|
{
|
|
// 隐藏所有面板
|
|
if (_welcomePanel != null) _welcomePanel.IsVisible = false;
|
|
if (_knowledgePanel != null) _knowledgePanel.IsVisible = false;
|
|
if (_projectPanel != null) _projectPanel.IsVisible = false;
|
|
if (_installPanel != null) _installPanel.IsVisible = false;
|
|
if (_settingsPanel != null) _settingsPanel.IsVisible = false;
|
|
|
|
// 显示目标面板
|
|
if (targetPanel != null)
|
|
{
|
|
targetPanel.IsVisible = true;
|
|
}
|
|
|
|
// 更新按钮样式
|
|
UpdateButtonStyles();
|
|
}
|
|
|
|
private void UpdateButtonStyles()
|
|
{
|
|
// 移除所有按钮的选中样式
|
|
_knowledgeButton?.Classes.Remove("selected");
|
|
_projectButton?.Classes.Remove("selected");
|
|
_installButton?.Classes.Remove("selected");
|
|
_settingsButton?.Classes.Remove("selected");
|
|
|
|
// 根据当前显示的面板添加选中样式
|
|
if (_knowledgePanel?.IsVisible == true)
|
|
_knowledgeButton?.Classes.Add("selected");
|
|
else if (_projectPanel?.IsVisible == true)
|
|
_projectButton?.Classes.Add("selected");
|
|
else if (_installPanel?.IsVisible == true)
|
|
_installButton?.Classes.Add("selected");
|
|
else if (_settingsPanel?.IsVisible == true)
|
|
_settingsButton?.Classes.Add("selected");
|
|
}
|
|
|
|
private void OnKnowledgeButtonClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
ShowPanel(_knowledgePanel);
|
|
}
|
|
|
|
private void OnProjectButtonClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
ShowPanel(_projectPanel);
|
|
}
|
|
|
|
private void OnInstallButtonClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
ShowPanel(_installPanel);
|
|
}
|
|
|
|
private void OnSettingsButtonClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
ShowPanel(_settingsPanel);
|
|
}
|
|
|
|
private void OnThemeComboBoxSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (_themeComboBox?.SelectedIndex != null)
|
|
{
|
|
var newTheme = _themeComboBox.SelectedIndex == 0 ? ThemeVariant.Dark : ThemeVariant.Light;
|
|
ThemeManager.SetTheme(newTheme);
|
|
}
|
|
}
|
|
|
|
private void OnThemeChanged(ThemeVariant theme)
|
|
{
|
|
UpdateThemeComboBox();
|
|
}
|
|
|
|
private void UpdateThemeComboBox()
|
|
{
|
|
if (_themeComboBox != null)
|
|
{
|
|
_themeComboBox.SelectedIndex = ThemeManager.CurrentTheme == ThemeVariant.Dark ? 0 : 1;
|
|
}
|
|
}
|
|
} |