Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.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# 将属性绑定到自定义ItemTemplate_C#_Wpf_Listview_Binding_Itemtemplate - Fatal编程技术网

C# 将属性绑定到自定义ItemTemplate

C# 将属性绑定到自定义ItemTemplate,c#,wpf,listview,binding,itemtemplate,C#,Wpf,Listview,Binding,Itemtemplate,我有一个ListView和一个自定义ItemTemplate(MyUserControl1) MyUserControl1.cs仅包含一个属性(My段落): 公共段落我的段落 { 得到 { 返回我的段落; } 设置 { _我的段落=值; 段落=新段落(); 对于(int i=0;i

我有一个ListView和一个自定义ItemTemplate(MyUserControl1)


MyUserControl1.cs仅包含一个属性(My段落):

公共段落我的段落
{
得到
{ 
返回我的段落;
}
设置
{
_我的段落=值;
段落=新段落();
对于(int i=0;i<\u myparagration.Inlines.Count;i++)
{
添加(_myparation.Inlines[i]);
richTextBlock.Blocks.Add(段落);
}
}
}
我得到的错误是:

未能分配给属性“App4.MyUserControl1.MyParaguation”


我已经从Flex迁移,所以我做了一些错误的事情,但我不知道在哪里。

为了绑定数据,目标属性必须是dependancProperty,所以为了使绑定工作正常,
myparagration
应该是UserControl中的dependancProperty,如下所示

 public Paragraph MyParagraph
  {
    get { return (Paragraph)this.GetValue(MyParagraphProperty); }
    set { this.SetValue(MyParagraphProperty, value); } 
  }
  public static readonly DependencyProperty MyParagraphProperty = DependencyProperty.Register(
    "MyParagraph", typeof(Paragraph), typeof(UserControl1),new PropertyMetadata(null));
public Paragraph MyParagraph
{
    get 
    { 
        return _MyParagraph; 
    }
    set 
    {
        _MyParagraph = value;
        Paragraph paragraph = new Paragraph();

        for (int i = 0; i < _MyParagraph.Inlines.Count; i++)
        {
            paragraph.Inlines.Add(_MyParagraph.Inlines[i]);
            richTextBlock.Blocks.Add(paragraph);
        }
    }
}
 public Paragraph MyParagraph
  {
    get { return (Paragraph)this.GetValue(MyParagraphProperty); }
    set { this.SetValue(MyParagraphProperty, value); } 
  }
  public static readonly DependencyProperty MyParagraphProperty = DependencyProperty.Register(
    "MyParagraph", typeof(Paragraph), typeof(UserControl1),new PropertyMetadata(null));