在加载XAML(或BAML)和接收根对象(例如Window)之间内部会发生什么?
首先出现在我脑海中的是Reflecton用于创建对象,设置其属性等等.但也许我错了?
也许有人可以解释如何在运行时解析和执行XAML/BAML,或者给出一篇包含解释的好文章的链接?
为了使我的问题更清楚一点,让我们讨论一下这个简短的例子:
<Button Margin="10">OK</Button>
Run Code Online (Sandbox Code Playgroud)
因此,解析器看到需要创建一个Button对象,其Margin属性必须设置为10并且其内容必须设置为"OK".怎么做的?通过使用Reflection(加上TypeConverters等)?
对于我正在使用XAML的项目.我已经将屏幕划分为不同的部分.我添加按钮的那一刻,我收到了一个错误.
错误:
'属性元素不能位于元素内容的中间'
我用于找到错误的按钮的代码:
<Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" />
Run Code Online (Sandbox Code Playgroud)
有谁知道问题是什么以及我如何解决它?
其余代码:
<Window x:Class="Pesten.View.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Image Grid.RowSpan="4" Grid.ColumnSpan="3" Stretch="Fill" Source="pestenbg.jpg" VerticalAlignment="Top" HorizontalAlignment="Center"/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="5*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Button x:Name="cntButton" Content="Connect" Grid.Column="1" Grid.Row="2" Click="cntButton_Click" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 在XAML解析的上下文中,我想知道解析器在类型定义NameScope时如何知道.
它完全依赖于INameScope接口,检查instance is INameScope?
它是否依赖于布尔属性XamlType.IsNameScope?
它是两者的混合吗?