VideoConcat/Views/MainWindow.xaml.cs
2025-08-12 00:13:45 +08:00

102 lines
3.1 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 System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using VideoConcat.Models;
using RadioButton = System.Windows.Controls.RadioButton;
namespace VideoConcat.Views
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainWindowModel();
// 窗口加载完成后执行
Loaded += MainView_Loaded;
}
public void MainView_Loaded(object sender, RoutedEventArgs e)
{
// 1. 为目标Grid创建列定义
SetupGridColumns(mainGrid);
// 2. 实例化已有视图(或获取已存在的视图实例)
var existingView = new VideoWindow(); // 这里是已有视图的实例
// 3. 将视图添加到指定列中例如第1列索引为1
AddViewToColumn(mainGrid, existingView);
}
/// <summary>
/// 为Grid设置列定义
/// </summary>
private void SetupGridColumns(Grid grid)
{
// 清空现有列(可选)
grid.Children.Clear();
}
/// <summary>
/// 将视图添加到Grid的指定列
/// </summary>
/// <param name="grid">目标Grid</param>
/// <param name="view">要添加的视图UserControl/FrameworkElement</param>
/// <param name="columnIndex">列索引从0开始</param>
private void AddViewToColumn(Grid grid, FrameworkElement view)
{
// 将视图添加到Grid的子元素中
grid.Children.Add(view);
}
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
this.DragMove();
}
}
private void RadioButton_Checked(object sender, RoutedEventArgs e)
{
if (sender is RadioButton radioButton)
{
if (radioButton.Name == "extract")
{
SetupGridColumns(mainGrid);
// 2. 实例化已有视图(或获取已存在的视图实例)
var existingView = new ExtractWindow(); // 这里是已有视图的实例
// 3. 将视图添加到指定列中例如第1列索引为1
AddViewToColumn(mainGrid, existingView);
}
if (radioButton.Name == "video")
{
// 1. 为目标Grid创建列定义
SetupGridColumns(mainGrid);
// 2. 实例化已有视图(或获取已存在的视图实例)
var existingView = new VideoWindow(); // 这里是已有视图的实例
// 3. 将视图添加到指定列中例如第1列索引为1
AddViewToColumn(mainGrid, existingView);
}
}
}
}
}