Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF-为什么我的UserControl停止工作?_C#_Wpf_User Controls_Code Behind - Fatal编程技术网

C# WPF-为什么我的UserControl停止工作?

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

WPF-为什么我的
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
,以在使用控件时实现更大的灵活性