Files
Z173/Views/MainWindow.xaml.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2026-06-13 14:16:34 +08:00
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();
}
2026-06-16 11:53:02 +08:00
2026-06-17 20:54:24 +08:00
private void StagesDataGrid_Loaded(object sender, RoutedEventArgs e)
{
var dataGrid = sender as DataGrid;
if (dataGrid == null) return;
2026-06-16 11:53:02 +08:00
2026-06-17 20:54:24 +08:00
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);
}
2026-06-16 11:53:02 +08:00
2026-06-13 14:16:34 +08:00
}
}