0

ListBoxコントロールへのバインドに問題があります。実際、私はApp.xaml.csにプロパティを持っています:

public partial class App : Application, INotifyPropertyChanged
{
    ObservableCollection<Panier> _panier = new ObservableCollection<Panier>();

    public ObservableCollection<Panier> PanierProperty
    {
        get { return _panier; }
        set
        {
            if (this._panier != value)
            {
                this._panier = value;
                NotifyPropertyChanged("PanierProperty");
            }
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged(String property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }
}

このプロパティには、ここの「Panierクラス」に子プロパティがあります。

public class Panier : INotifyPropertyChanged
{
    private string _nom;
    private string _category;
    private int _prix;

    public string Nom
    {
        get { return _nom; }
        set
        {
            if (this._nom != value)
            {
                this._nom = value;
                NotifyPropertyChanged("Nom");
            }
        }
    }

    public string Category
    {
        get { return _category; }
        set
        {
            if (this._category != value)
            {
                this._category = value;
                NotifyPropertyChanged("Category");
            }
        }
    }

    public int Prix
    {
        get { return _prix; }
        set
        {
            if (this._prix != value)
            {
                this._prix = value;
                NotifyPropertyChanged("Prix");
            }
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged(String property)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }
}

MainWindow.xamlページで、ListBoxをPanierProperty(親プロパティ)にバインドしています:

<telerik:RadListBox x:Name="PanierLB" Grid.Row="1" Height="200" Width="350" Margin="0 300 0 0"
    ItemsSource="{Binding PanierProperty, Source={x:Static Application.Current}}"
    DisplayMemberPath="{Binding Path=PanierProperty.Nom, Source={x:Static Application.Current}}">
</telerik:RadListBox>

私の問題は、PanierPropertyがリストボックスにバインドされていることです。リストボックスにDesign.Panier Design.PanierDesign.Panierなどのアイテムが表示されます。PanierProperty.Nom(Nomは子プロパティ)を表示する方法がわかりません。リストボックス。

誰かが助けてくれます。

4

1 に答える 1

1

表示DisplayMemberPathしたいプロパティの名前を使用する場合:

<telerik:RadListBox
    ...
    DisplayMemberPath="Nom"
于 2012-06-17T01:53:53.690 に答える