using CommunityToolkit.Mvvm.ComponentModel; using OpenTap; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace OpenTapEditor { [ObservableObject] public partial class BreakConditionContext { [ObservableProperty] private ITestStepParent source; public bool CanEdit { get => source != null && BreakConditionProperty.GetBreakCondition(source) != BreakCondition.Inherit; set { if (!value) { Value = BreakCondition.Inherit; } else { Value = BreakCondition.BreakOnError; } OnPropertyChanged(); } } public BreakCondition? Value { get => source == null ? null : BreakConditionProperty.GetBreakCondition(source); set { BreakConditionProperty.SetBreakCondition(source, value.Value); OnPropertyChanged(); } } partial void OnSourceChanged(ITestStepParent value) { OnPropertyChanged(nameof(CanEdit)); OnPropertyChanged(nameof(Value)); } } /// /// BreakConditionCtrl.xaml 的交互逻辑 /// [ObservableObject] public partial class BreakConditionCtrl : UserControl { [ObservableProperty] private BreakConditionContext context = new BreakConditionContext(); public static readonly DependencyProperty SourceProperty = DependencyProperty.RegisterAttached("SourceProperty", typeof(object), typeof(BreakConditionCtrl), new PropertyMetadata(null, OnSourceChanged)); private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (d is BreakConditionCtrl element && e.Property == SourceProperty && e.NewValue is ITestStepParent tsp) { element.Context.Source = tsp; } } public ITestStepParent Source { get => (ITestStepParent)GetValue(SourceProperty); set => SetValue(SourceProperty, value); } public BreakConditionCtrl() { DataContext = Context; InitializeComponent(); } } }