2012-04-11 11 views
0

として、私はWrapPanelと私のItemsControlを設定しました:私のデータが適切に作成WrapPanelでItemsControlをバインドしますか?

private class mark_item 
    { 
     public mark_item() 
     { 
      this.timestamp= ""; 
     } 
     public string timestamp { get; set; } 
    } 

    private List<mark_item> marks; 

    itemsMarks.ItemsSource = marks; 

リストマークです、そしてWrapPanelが実際のアイテム数を含むリストではありますが、

  <ItemsControl Grid.Row="1" Height="200" Width="420" HorizontalAlignment="Center" Name="itemsMarks" VerticalAlignment="Top"> 
      <ItemsControl.ItemsPanel> 
       <ItemsPanelTemplate> 
        <toolkit:WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center"/> 
       </ItemsPanelTemplate> 
      </ItemsControl.ItemsPanel> 
      <ItemsControl.ItemTemplate> 
       <DataTemplate> 
        <StackPanel> 
        <Image Margin="1" 
           VerticalAlignment="Center" 
           Source="Images/markg.png" 
           Width="70" 
           Height="70" /> 
         <TextBlock TextWrapping="Wrap" Foreground="Black" Text="{Binding timestamp}" FontSize="14" HorizontalAlignment="Center" /> 
        </StackPanel> 
       </DataTemplate> 
      </ItemsControl.ItemTemplate> 
     </ItemsControl> 

TextBlockはTextプロパティセットを取得しません。

私には何が欠けていますか?あなたがpublic、ないprivateとしてあなたmark_itemクラスを宣言する必要が

おかげ

+0

あなたの 'ItemsControl'とリストデータの間に適切なバインディングを作成していません。 'ItemsSource'プロパティを設定するだけでは十分ではありません。 – Bernard

+0

あなたのアプリケーションをデバッグする場合はビジュアルスタジオのアウトプットウィンドウにいくつかのバインディング警告が表示されるはずです。 – gbanfill

答えて

1

Silverlightでのデータバインディングは、クラスとプロパティpublicにしかアクセスできません。クラスprivateを宣言することで、Silverlightがアクセスできなくなります。

私はあなたのコードをそのまま使用しましたが、あなたが記述したのと同じ動作を見ました。適切な数のアイテムがItemsControlに表示されていましたが、テキストがありませんでした。また、Visual Studio/Visual Web Developer Expressの出力ウィンドウに次のメッセージが表示されました。 (メッセージ自体は十分な長さであるように私は、スタックトレースを省略しました):私はクラスpublicを宣言

System.Windows.Data Error: Cannot get 'timestamp' value (type 'System.String') from 'PrivateClassProblem.MainPage+mark_item' (type 'PrivateClassProblem.MainPage+mark_item'). BindingExpression: Path='timestamp' DataItem='PrivateClassProblem.MainPage+mark_item' (HashCode=12905972); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String').. System.MethodAccessException: Attempt by method 'System.Windows.CLRPropertyListener.get_Value()' to access method 'PrivateClassProblem.MainPage+mark_item.get_timestamp()' failed.

は、問題が去っていきました。

+0

うん、馬鹿:)ありがとう。 – Marin

関連する問題