标签:eve 代码 pat debug efi message isp 如何 告诉
XAML(extensible application markup language)发音为“zammel”,是用于实例化.net对象的标记语言。
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfXaml { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); LoadXaml(); } private void LoadXaml() { using var fileReader = new FileStream("../../../Test.xaml", FileMode.Open); DependencyObject rootElement = (DependencyObject)XamlReader.Load(fileReader); this.Content = rootElement; var btn = (Button)LogicalTreeHelper.FindLogicalNode(rootElement, "A"); if (btn != null) btn.Click += Btn_Click; } private void Btn_Click(object sender, RoutedEventArgs e) { MessageBox.Show("showMe"); } } }
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfXaml"> <Button Content="123" Width="100" Height="30" Name="A"></Button> <Button Content="456" Width="100" Height="30" Name="B"></Button> </StackPanel>
注意:这种直接加载xaml的方式并没有使用打包成资源的baml速度快
<Window x:Class="WpfXaml.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfXaml" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> </Grid> </Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"是WPF核心名称空间,包含WPF所以类,包括构建用户界面的控件
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"是XAML名称空间,包含XAML的实用特效
x:Class="WpfXaml.MainWindow"
Class特性告诉XAML解释器用指定名称生成一个新类,该类是主窗口的部分类(partial,即MainWindow.g.i.cs)。该类包含了 InitializeComponent()方法。
<Grid x:Name="Grid"> </Grid>
Name特性告诉XAML解释器为部分类添加名称为Grid的字段
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")] internal System.Windows.Controls.Grid Grid;
标签:eve 代码 pat debug efi message isp 如何 告诉
原文地址:https://www.cnblogs.com/doomclouds/p/13284202.html