C# WPF-为什么我的UserControl停止工作?
WPF-为什么我的C# WPF-为什么我的UserControl停止工作?,c#,wpf,user-controls,code-behind,C#,Wpf,User Controls,Code Behind,WPF-为什么我的UserControl在取消注释注释行时停止工作? 当我注释我的控件时,它在开始时添加了行,当我取消注释时,它没有通过LoadRow()添加任何行,甚至尝试通过一些textbox和按钮功能在运行时添加行 从自定义UserControl的代码隐藏: public void LoadRows() { Rows.Add(new Row("221 331,44", GetOutputFromInput)); Rows.Add(new Ro
UserControl
在取消注释注释行时停止工作?
当我注释我的控件时,它在开始时添加了行,当我取消注释时,它没有通过LoadRow()
添加任何行,甚至尝试通过一些textbox
和按钮
功能在运行时添加行
从自定义UserControl的代码隐藏:
public void LoadRows()
{
Rows.Add(new Row("221 331,44", GetOutputFromInput));
Rows.Add(new Row("2 331,44", GetOutputFromInput));
Rows.Add(new Row("331,44", GetOutputFromInput));
Rows.Add(new Row("0,44", GetOutputFromInput));
Rows.Add(new Row { Input = "333", Output = "555"});
Rows.Add(new Row { Input = "333", Output = "555"});
}
//public DependencyProperty RowsProperty = DependencyProperty.Register("Rows", typeof(ObservableCollection<Row>), typeof(TriggerListAdd));
public ObservableCollection<Row> Rows
{
get;
set;
}
public void LoadRows()
{
添加(新行(“221 331,44”,GetOutputFromInput));
添加(新行(“2331,44”,GetOutputFromInput));
添加(新行(“331,44”,GetOutputFromInput));
添加(新行(“0,44”,GetOutputFromInput));
添加(新行{Input=“333”,Output=“555”});
添加(新行{Input=“333”,Output=“555”});
}
//public dependencProperty RowsProperty=dependencProperty.Register(“行”、typeof(observeCollection)、typeof(TriggerListAdd));
公共可观测收集行
{
得到;
设置
}
仅通过取消注释该行,无法获得依赖项属性。您还必须编写正确的CLR属性包装:
public DependencyProperty RowsProperty = DependencyProperty.Register(
nameof(Rows),
typeof(ObservableCollection<Row>),
typeof(TriggerListAdd));
public ObservableCollection<Row> Rows
{
get { return (ObservableCollection<Row>)GetValue(RowsProperty);
set { SetValue(RowsProperty, value);
}
公共DependencyProperty行属性=DependencyProperty.Register(
(行)名称,
类型(可观测采集),
类型(TriggerListAdd));
公共可观测收集行
{
获取{return(observetecollection)GetValue(RowsProperty);
set{SetValue(RowsProperty,value);
}
我还建议将属性的类型更改为IEnumerable
,以在使用控件时实现更大的灵活性