我是Windows应用程序开发的新手。我正在创建一个自定义UserControl,其他用户将可以在其应用程序中使用它。我想对控件进行配置,以便在其中放置任何内容时,它将分配给Content以外的其他属性。为了给您更好的解释,如果您编写以下代码:

<Button>Hello, world!</Button>


就像您已经写过这样:

<Button Content="Hello, world!"/>


是否可以让XAML解析器将控件的内容设置为Content以外的属性,或者这不可能吗?

谢谢。

最佳答案

您可以使用ContentPropertyAttribute:

[ContentProperty("DefaultProperty")]


更多信息:https://msdn.microsoft.com/en-us/library/system.windows.markup.contentpropertyattribute.aspx

关于c# - 如何在XAML中使默认属性不同于Content?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35119258/

10-14 15:54
查看更多