如何从App.xaml设置与childproperty的绑定

时间:2012-06-17 00:52:21

标签: c# wpf binding telerik inotifypropertychanged

我的Binding到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绑定到我的Listbox我看到列表框中的项目如Design.Panier Design.Panier Design.Panier 等等... 我不知道如何在ListBox上显示PanierProperty.Nom(Nom是子属性)。

有人可以帮忙。

1 个答案:

答案 0 :(得分:1)

DisplayMemberPath中,使用您只想显示的媒体资源名称:

<telerik:RadListBox
    ...
    DisplayMemberPath="Nom"