0

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 から移行したので、何か間違ったことをしていますが、どこにあるのかわかりません。

4

1 に答える 1

0

データをバインドするには、ターゲット プロパティが DependancyProperty である必要があるため、このバインディングを機能させるには、MyParagraph以下のように UserControl で依存プロパティにする必要があります。

 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));
于 2013-10-02T15:40:05.740 に答える