我在XAML中看到了别人编写的以下UserControl声明:
据我所知,x:Name属性用于在XAML中为变量声明者命名,以便能够从代码或XAML本身引用它。
考虑到这是根元素,我不明白为什么要使用这个名称(在后台代码中我将使用“this”,在XAML中我可以使用“RelativeSource”等)。
有什么提示吗?
<core:UserControlBase x:Class="xxxx"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:core="clr-namespace:Agn.Word.AddIn.Core.Presentation;assembly=Agn.Word.AddIn.Core"
x:Name="aName">
据我所知,x:Name属性用于在XAML中为变量声明者命名,以便能够从代码或XAML本身引用它。
考虑到这是根元素,我不明白为什么要使用这个名称(在后台代码中我将使用“this”,在XAML中我可以使用“RelativeSource”等)。
有什么提示吗?
RelativeSource
不太可靠,你必须使用元素名称。 - SinatrRelativeSource
的情况示例(而x:Name
完美地工作)。 - Sinatr