41 lines
957 B
C#
41 lines
957 B
C#
using System.IO;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Markup;
|
|
|
|
namespace WPF基础_1_2_和xaml一起创建;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public MainWindow(string xamlFile)
|
|
{
|
|
Width = Height = 285;
|
|
Left = Top = 100;
|
|
Title = "混合xaml";
|
|
|
|
DependencyObject rootElement;
|
|
using (var fileStream = new FileStream(xamlFile, FileMode.Open))
|
|
{
|
|
rootElement = (DependencyObject)XamlReader.Load(fileStream);
|
|
}
|
|
|
|
Content = rootElement;
|
|
|
|
_button = (Button)LogicalTreeHelper.FindLogicalNode(rootElement, "_button");
|
|
|
|
_button.Click += Button_OnClick;
|
|
}
|
|
|
|
private void Button_OnClick(object sender, RoutedEventArgs eventArgs)
|
|
{
|
|
_button!.Content = "栓Q";
|
|
}
|
|
} |