SSPC-Tester/SSPCTester.UI/Views/CurvePopupWindow.xaml.cs

52 lines
1.9 KiB
C#
Raw Normal View History

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using SSPCTester.UI.Controls;
using SSPCTester.UI.ViewModels;
namespace SSPCTester.UI.Views;
public partial class CurvePopupWindow : Window
{
public CurvePopupWindow()
{
InitializeComponent();
}
public CurvePopupWindow(CurveTestViewModel vm, string? curveKind)
: this()
{
DataContext = vm;
ConfigureCurve(curveKind);
}
private void ConfigureCurve(string? curveKind)
{
bool isFalling = string.Equals(curveKind, "Falling", StringComparison.OrdinalIgnoreCase);
string title = isFalling ? "关断曲线电压下降10% 阈值)" : "开启曲线电压上升90% 阈值)";
Title = title;
TitleRun.Text = $"{title} ";
CurveTitleText.Text = title;
CurvePlot.IsRising = !isFalling;
CurvePlot.SetBinding(CurvePlotControl.CurveProperty, new Binding(isFalling ? "FallingCurve" : "RisingCurve"));
CurvePlot.SetBinding(CurvePlotControl.ViewStartMsProperty, new Binding(isFalling ? "FallingViewStartMs" : "RisingViewStartMs"));
CurvePlot.SetBinding(CurvePlotControl.ViewEndMsProperty, new Binding(isFalling ? "FallingViewEndMs" : "RisingViewEndMs"));
StartTextBox.SetBinding(TextBox.TextProperty, new Binding(isFalling ? "FallingViewStartMs" : "RisingViewStartMs")
{
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
TargetNullValue = ""
});
EndTextBox.SetBinding(TextBox.TextProperty, new Binding(isFalling ? "FallingViewEndMs" : "RisingViewEndMs")
{
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
TargetNullValue = ""
});
ResetButton.SetBinding(Button.CommandProperty, new Binding(isFalling ? "ResetFallingCurveViewCommand" : "ResetRisingCurveViewCommand"));
}
private void Close_Click(object sender, RoutedEventArgs e) => Close();
}