我的自定义属性中未启用数据绑定和依赖属性
我想创建自己的 silverlight dll 以添加到另一个项目。
为此,我创建了一个 Silverlight LibraryControl 包含一些文本框和组合框以及对象列表(可观察集合类型)
我尝试为它们创建 DependencyProperty 类型对象。
现在我希望在我的第二个项目中我能够使用数据绑定填充这些属性,但是当我将其添加到项目中时,数据绑定和其他一些属性被禁用。
我的代码如下所示,
public static readonly DependencyProperty DPDescription = DependencyProperty.Register("DesCription", typeof(string), typeof(WorkFlowPfazar), new PropertyMetadata(Description_Changed));
public string Description
{
get
{
return (string)GetValue(DPDescription);
}
set
{
SetValue(DPDescription, value);
}
}
private static void Description_Changed(DependencyObject Object, DependencyPropertyChangedEventArgs Args)
{
WorkFlowPfazar wf = Object as WorkFlowPfazar;
if (wf == null)
return;
wf.tbDescription.Text = Args.NewValue.ToString();
}
public static readonly DependencyProperty DPFormNames = DependencyProperty.Register("FormNames", typeof(ObservableCollection<string>), typeof(WorkFlowPfazar),new PropertyMetadata(FormNames_Change));
public ObservableCollection <object> FormNames
{
get
{
return (ObservableCollection<object>)GetValue(DPFormNames);
}
set
{
SetValue(DPFormNames, (ObservableCollection <object>)value);
}
}
private static void FormNames_Change(DependencyObject Object, DependencyPropertyChangedEventArgs Args)
{
WorkFlowPfazar wf = Object as WorkFlowPfazar;
if (wf == null)
return;
wf.cbFormName.ItemsSource = Args.NewValue as ObservableCollection <object>;
}
还有一些类似的属性。但我将两个一发布到简单的问题。 问题是什么?或者我该怎么办?
I wants to create my own silverlight dll to add to another project.
for this reasin I create a Silverlight LibraryControl Contains some textBox and combobox and also a list of objects ( observable collection type)
I try to Create DependencyProperty Type objects for them.
Now I wants in My second Projects I could be able to fill these Properties with DataBinding but wen I add this to Project the Databinding and some Others was disable to use.
my codes is like below
public static readonly DependencyProperty DPDescription = DependencyProperty.Register("DesCription", typeof(string), typeof(WorkFlowPfazar), new PropertyMetadata(Description_Changed));
public string Description
{
get
{
return (string)GetValue(DPDescription);
}
set
{
SetValue(DPDescription, value);
}
}
private static void Description_Changed(DependencyObject Object, DependencyPropertyChangedEventArgs Args)
{
WorkFlowPfazar wf = Object as WorkFlowPfazar;
if (wf == null)
return;
wf.tbDescription.Text = Args.NewValue.ToString();
}
public static readonly DependencyProperty DPFormNames = DependencyProperty.Register("FormNames", typeof(ObservableCollection<string>), typeof(WorkFlowPfazar),new PropertyMetadata(FormNames_Change));
public ObservableCollection <object> FormNames
{
get
{
return (ObservableCollection<object>)GetValue(DPFormNames);
}
set
{
SetValue(DPFormNames, (ObservableCollection <object>)value);
}
}
private static void FormNames_Change(DependencyObject Object, DependencyPropertyChangedEventArgs Args)
{
WorkFlowPfazar wf = Object as WorkFlowPfazar;
if (wf == null)
return;
wf.cbFormName.ItemsSource = Args.NewValue as ObservableCollection <object>;
}
there is some more Properties like these. but I post Two Ones to simle question.
what is the problem? or what shal I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Silverlight 中,编码约定很重要。保存属性的 DependencyProperty 值的字段应该与属性具有相同的名称以及后缀“Property”。此外,传递给
Register
方法的名称也应该与属性的名称匹配。例如,您的描述属性应如下所示:-In Silverlight coding conventions matter. A field that holds the
DependencyProperty
value for a property should simply have the same name as the property along with the suffix "Property". Also the name passed to theRegister
method should also match the name of the property. For example your Description property should look like this:-