0

私のバインディングのほとんどは正常に動作していますが、次の 1 つだけが表示されます: Test.Models.PersonModel

私がバインドしたいプロパティ (「名前」) は、このクラスにあります。

ここで私がバインドする部分:

<ItemsControl ItemsSource="{Binding Persons}">
    <StackPanel Margin="24, 4, 4, 4"
                Orientation="Horizontal">   
       <TextBlock FontSize="{StaticResource PhoneFontSizeExtraLarge}"
                  FontFamily="{StaticResource PhoneFontFamilyLight}"
                  Text="{Binding Name}" 
                  VerticalAlignment="Center"/>
    </StackPanel>
</ItemsControl>

Persons は、PersonModel タイプの OberservableCollection です。PersonModel のコードは次のとおりです。

public class PersonModel : INotifyPropertyChanged
{
    private string _name = null;

    public string Name
    {
        get { return _name; }
        set { _name = value; NotifyPropertyChanged("Name"); }
    }
    private BitmapImage _profilpicture = null;

    public BitmapImage ProfilPicture
    {
        get { return _profilpicture; }
        set { _profilpicture = value; NotifyPropertyChanged("ProfilPicture"); }
    }

    #region PropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    #endregion
}
4

1 に答える 1

0

ItemTemplate( msdn )を使用する必要があります。

<ItemsControl ItemsSource="{Binding Persons}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel  Margin="24, 4, 4, 4"  
                         Orientation="Horizontal">
                 <TextBlock FontSize="{StaticResource PhoneFontSizeExtraLarge}"
                            FontFamily="{StaticResource PhoneFontFamilyLight}"
                            Text="{Binding Name}" 
                            VerticalAlignment="Center"/>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>
于 2013-10-26T17:32:13.993 に答える