首先,我要感谢大家提供的所有精彩信息。我不得不承认 - StackOverflow 一直是可用的最好的同伴导师资源,因此它为我提供了比......“大学”4 年更多的知识。谢谢!
我正在使用一个控件,该控件具有一个对象集合属性。
public class UserParameter
{
string DisplayName { get; set; }
string Property { get; set; }
string Type { get; set; }
}
public class ParameterBuilder: UserControl
{
private ObservableCollection<UserParameter> parameters;
//alright - this is really dependency property.
//described as property just for simplicity.
public ObservableCollection<UserParamter> Parameters
{
get { return this.parameters; }
set { this.parameters = value; }
}
}
所以这个问题的核心是弄清楚如何在 Xaml 中创建这个集合。例如:
<custom:ParameterBuilder Name="Parameter">
<custom:ParameterBuilder.Parameters>
<custom:UserParameter DisplayName="Test 0" Property="Size" Type="String"/>
<custom:UserParameter DisplayName="Test 1" Property="Value" Type="Decimal"/>
</custom:ParameterBuilder.Parameters>
</custom:ParameterBuilder>
这可能吗?如果可能,我该怎么做?
最佳答案
如果您使用的是 .NET 4.0,您应该能够使用 x:TypeArguments 参数 (part of the XAML2009 spec) 引用泛型 - 因此您的参数中的 Observable 集合将声明为:
<ObservableCollection x:TypeArguments="UserParameter">
<l:UserParameter DisplayName="Test 0" Property="Size" Type="String" />
<l:UserParameter DisplayName="Test 1" Property="Value" Type="Decimal" />
</ObservableCollection />
关于c# - Silverlight 4 - 通过 XAML 声明/填充控件的集合属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6297444/