我有一个 ListView 和一个自定义 ItemTemplate (MyUserControl1)。
<ListView Name="listView" HorizontalAlignment="Left" Height="454" Margin="656,147,0,-461" VerticalAlignment="Top" Width="337">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,0,0,0">
<TextBlock Text="{Binding text}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"/>
<local:MyUserControl1 MyParagraph="{Binding paragraph}"></local:MyUserControl1>
<TextBlock Text="test" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MyUserControl1.cs 仅包含一个属性(MyParagraph):
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);
}
}
}
我得到的错误是:
未能分配给属性“App4.MyUserControl1.MyParagraph”。
我已经从 Flex 迁移,所以我做错了什么,但我不知道在哪里。