using System.Windows.Input; using Microsoft.UI.Xaml.Automation; using XFEEDToolBox.Core.Galaxy; namespace XFEEDToolBox.Controls; public sealed partial class GalaxyFilterPanel { public static readonly DependencyProperty MissionTargetsProperty=DependencyProperty.Register(nameof(MissionTargets),typeof(IReadOnlyList),typeof(GalaxyFilterPanel),new PropertyMetadata(null,Changed)); public static readonly DependencyProperty MissionsStatusProperty=DependencyProperty.Register(nameof(MissionsStatus),typeof(string),typeof(GalaxyFilterPanel),new PropertyMetadata("",Changed)); public static readonly DependencyProperty SelectMissionCommandProperty=DependencyProperty.Register(nameof(SelectMissionCommand),typeof(ICommand),typeof(GalaxyFilterPanel),new PropertyMetadata(null,Changed)); public IReadOnlyList MissionTargets {get=>(IReadOnlyList?)GetValue(MissionTargetsProperty)??[];set=>SetValue(MissionTargetsProperty,value);} public string MissionsStatus {get=>(string)GetValue(MissionsStatusProperty);set=>SetValue(MissionsStatusProperty,value);} public ICommand? SelectMissionCommand {get=>(ICommand?)GetValue(SelectMissionCommandProperty);set=>SetValue(SelectMissionCommandProperty,value);} private readonly TextBlock missionsStatus=new(){FontSize=11,TextWrapping=TextWrapping.Wrap}; private readonly StackPanel missionTargets=new(){Spacing=5}; private IReadOnlyList? renderedMissionTargets; private ICommand? renderedMissionCommand; private FrameworkElement BuildMissionControls() { var content=new StackPanel{Spacing=6};content.Children.Add(missionsStatus);content.Children.Add(missionTargets); return new Expander{Header="原游戏任务逐条定位",Content=content,HorizontalAlignment=HorizontalAlignment.Stretch,HorizontalContentAlignment=HorizontalAlignment.Stretch}; } private void RefreshMissionControls() { missionsStatus.Text=MissionsStatus; if(ReferenceEquals(renderedMissionTargets,MissionTargets)&&ReferenceEquals(renderedMissionCommand,SelectMissionCommand))return; renderedMissionTargets=MissionTargets;renderedMissionCommand=SelectMissionCommand;missionTargets.Children.Clear(); foreach(var target in MissionTargets) { var text=new TextBlock{Text=target.Label,FontSize=12,TextWrapping=TextWrapping.Wrap}; var button=new Button{Content=text,Command=SelectMissionCommand,CommandParameter=target,IsEnabled=target.SystemAddress is not null,HorizontalAlignment=HorizontalAlignment.Stretch,HorizontalContentAlignment=HorizontalAlignment.Stretch};AutomationProperties.SetName(button,"定位原任务 "+target.MissionId);missionTargets.Children.Add(button); } } }