Files
Z173/Views/MainWindow.xaml.cs
2026-06-17 20:54:24 +08:00

61 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AciTester.ViewModels;
using CommunityToolkit.Mvvm.Input;
using System.Text;
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 AciTester.Views
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += (s, e) =>
{
var keyGesture = new KeyGesture(Key.P, ModifierKeys.Control);
var inputBinding = new InputBinding(
new RelayCommand(OpenConfigWindow),
keyGesture);
this.InputBindings.Add(inputBinding);
};
}
private void OpenConfigWindow()
{
var vm = (MainViewModel)this.DataContext;
var configVm = new ConfigViewModel(vm._plcService, vm._config, vm.Calibration);
var win = new ConfigWindow { DataContext = configVm, Owner = this };
win.ShowDialog();
}
private void StagesDataGrid_Loaded(object sender, RoutedEventArgs e)
{
var dataGrid = sender as DataGrid;
if (dataGrid == null) return;
this.Dispatcher.BeginInvoke(new Action(() =>
{
double availableHeight = dataGrid.ActualHeight - 25 - 8; // 表头约28px边框约8px
if (dataGrid.Items.Count > 0)
{
double rowHeight = availableHeight / dataGrid.Items.Count;
dataGrid.RowHeight = Math.Max(rowHeight, 25); // 最小行高设为28px
}
}), System.Windows.Threading.DispatcherPriority.Loaded);
}
}
}