You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.0 KiB

using ReactiveUI.Avalonia;
using Avalonia.Markup.Xaml;
using Avalonia.Controls;
using AuroraDesk.Presentation.ViewModels.Pages;
using HeroIconsAvalonia.Controls;
using ReactiveUI;
using HeroIconsAvalonia.Enums;
namespace AuroraDesk.Presentation.Views.Pages;
public partial class UdpServerPageView : ReactiveUserControl<UdpServerPageViewModel>
{
private Button? _toggleButton;
private HeroIcon? _toggleIcon;
private Expander? _clientListExpander;
public UdpServerPageView()
{
InitializeComponent();
this.WhenActivated(disposables =>
{
// 查找控件
_toggleButton = this.FindControl<Button>("ToggleButton");
_toggleIcon = this.FindControl<HeroIcon>("ToggleIcon");
_clientListExpander = this.FindControl<Expander>("ClientListExpander");
if (_toggleButton != null && _clientListExpander != null)
{
// 绑定点击事件
_toggleButton.Click += (s, e) =>
{
if (_clientListExpander != null)
{
_clientListExpander.IsExpanded = !_clientListExpander.IsExpanded;
UpdateToggleIcon();
}
};
// 监听 Expander 状态变化
_clientListExpander.PropertyChanged += (s, e) =>
{
if (e.Property.Name == nameof(Expander.IsExpanded))
{
UpdateToggleIcon();
}
};
// 初始化图标状态
UpdateToggleIcon();
}
});
}
private void UpdateToggleIcon()
{
if (_toggleIcon != null && _clientListExpander != null)
{
_toggleIcon.Type = _clientListExpander.IsExpanded
? IconType.ChevronDown
: IconType.ChevronRight;
}
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}