61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
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);
|
||
}
|
||
|
||
}
|
||
} |