WPF-Base/WPF基础-1-2-和xaml一起创建/MainWindow.xaml.cs

41 lines
957 B
C#
Raw Normal View History

2024-12-30 10:41:43 +08:00
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
namespace WPF基础_1_2_和xaml一起创建;
/// <summary>
2025-01-25 23:06:31 +08:00
/// Interaction logic for MainWindow.xaml
2024-12-30 10:41:43 +08:00
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public MainWindow(string xamlFile)
{
Width = Height = 285;
Left = Top = 100;
Title = "混合xaml";
2025-01-25 23:06:31 +08:00
DependencyObject rootElement;
using (var fileStream = new FileStream(xamlFile, FileMode.Open))
2024-12-30 10:41:43 +08:00
{
rootElement = (DependencyObject)XamlReader.Load(fileStream);
}
Content = rootElement;
2025-01-25 23:06:31 +08:00
_button = (Button)LogicalTreeHelper.FindLogicalNode(rootElement, "_button");
2024-12-30 10:41:43 +08:00
_button.Click += Button_OnClick;
}
2025-01-25 23:06:31 +08:00
2024-12-30 10:41:43 +08:00
private void Button_OnClick(object sender, RoutedEventArgs eventArgs)
{
_button!.Content = "栓Q";
}
}