C# 在具有Dependency属性的自定义属性中未启用数据绑定
我想创建自己的silverlight dll以添加到另一个项目中 为此,我创建了一个Silverlight Library控件,其中包含一些文本框和组合框,以及一个对象列表(可观察的集合类型) 我尝试为它们创建DependencyProperty类型的对象 现在我想在我的第二个项目中,我可以用数据绑定填充这些属性,但我将其添加到项目中,数据绑定和其他一些被禁用 我的代码如下C# 在具有Dependency属性的自定义属性中未启用数据绑定,c#,silverlight,silverlight-4.0,dependency-properties,C#,Silverlight,Silverlight 4.0,Dependency Properties,我想创建自己的silverlight dll以添加到另一个项目中 为此,我创建了一个Silverlight Library控件,其中包含一些文本框和组合框,以及一个对象列表(可观察的集合类型) 我尝试为它们创建DependencyProperty类型的对象 现在我想在我的第二个项目中,我可以用数据绑定填充这些属性,但我将其添加到项目中,数据绑定和其他一些被禁用 我的代码如下 public static readonly DependencyProperty DPDescription = De
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>;
}
public static readonly dependencProperty DPDescription=dependencProperty.Register(“DesCription”、typeof(string)、typeof(WorkFlowPfazar)、new PropertyMetadata(DesCription_Changed));
公共字符串描述
{
收到
{
返回(字符串)GetValue(DPDescription);
}
设置
{
设置值(DPDescription,value);
}
}
私有静态无效描述\u已更改(DependencyObject对象、DependencyPropertyChangedEventArgs参数)
{
WorkFlowPfazar wf=对象作为WorkFlowPfazar;
如果(wf==null)
回来
wf.tbDescription.Text=Args.NewValue.ToString();
}
public static readonly dependencProperty DPFormNames=dependencProperty.Register(“FormNames”、typeof(observeCollection)、typeof(WorkFlowPfazar)、new PropertyMetadata(FormNames_Change));
公共可观察集合FormName
{
收到
{
返回(ObservableCollection)GetValue(DPFormNames);
}
设置
{
SetValue(DPFormNames,(ObservableCollection)值);
}
}
私有静态void FormNames\u更改(DependencyObject对象、DependencyPropertyChangedEventArgs参数)
{
WorkFlowPfazar wf=对象作为WorkFlowPfazar;
如果(wf==null)
回来
wf.cbFormName.ItemsSource=Args.NewValue作为ObservableCollection;
}
还有一些类似的属性。但我贴了两张单子来回避这个问题。
有什么问题?或者我该怎么做?在Silverlight中,编码约定很重要。保存属性的
DependencyProperty
值的字段应该与属性具有相同的名称以及后缀“property”。此外,传递给寄存器的名称也应与属性的名称匹配。例如,您的描述属性应如下所示:-
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register(
"Description",
typeof(string),
typeof(WorkFlowPfazar),
new PropertyMetadata(Description_Changed));
public string Description
{
get
{
return (string)GetValue(DescriptionProperty);
}
set
{
SetValue(DescriptionProperty, 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();
}
我能和科兹谈谈吗?