【发布时间】:2021-03-19 12:36:47
【问题描述】:
在 XAML 中,有没有办法设置属性的属性?
这里有一个例子来说明:
public class SomeControl : Control
{
public SomeType SomeProperty { get; } = new SomeType(); // Property deliberately read only
}
public class SomeType
{
public string Name { get; set; }
}
在下面的 XAML 中,我想设置 «SomeProperty» 属性的 «Name» 值,而不向 «SomeProperty» 添加设置器,因此不创建 «SomeType» 的新 XAML 实例。
<ns:SomeControl SomeProperty.Name ="Foo"> <!-- here is the idea, but does not compile -->
</ns:SomeControl>
问候
【问题讨论】:
-
不可能...这样的语法适用于附加属性
-
我知道附加属性的这种语法,但是没有其他语法可以满足这种需要吗?
-
有什么好的理由让这不可能吗?
-
我不知道?也许这样的语法是针对附加属性的事实,它搜索
SomeProperty和SomeProperty.Name="Foo"类型的父级就像SomeProperty.SetName(control, "Foo")