[英]How can i set binding to childproperty from App.xaml
I have a problem with my Binding to a ListBox Control. 我对列表框控件的绑定有问题。 Actually i have a Property in App.xaml.cs :
实际上我在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));
}
}
}
this property have a child properties in the "Panier class" here: 此属性在“ 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));
}
}
}
and in my MainWindow.xaml page i have my ListBox bound to PanierProperty(parent 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>
my problem is that PanierProperty is bound to my Listbox i see items in the listbox like Design.Panier Design.Panier Design.Panier etc... I dont know how to get the PanierProperty.Nom(Nom is the child property) to show on the ListBox. 我的问题是PanierProperty绑定到我的列表框,我在列表框中看到诸如Design.Panier Design.Panier Design.Panier等的项目...我不知道如何获取PanierProperty.Nom(Nom是子属性)来显示列表框。
Someone can help please. 有人可以帮忙。
In DisplayMemberPath
use the name of property you want to show only: 在
DisplayMemberPath
使用仅显示的属性名称:
<telerik:RadListBox
...
DisplayMemberPath="Nom"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.