我有一个复杂的文章对象,其中包含一个ArticleLocation类型的位置列表。我需要在GridView中的组合框中显示这些位置:
public class Article : INotifyPropertyChanged
{
private int sapNumber;
private string descript;
private ObservableCollection<ArticleLocation> locations;
private ArticleLocation selectedLocation;
public int SAPNumber
{
get => sapNumber;
set
{
if (sapNumber != value)
{
sapNumber = value;
RaisePropertyChanged("SAPNumber");
}
}
}
public string Description
{
get => descript;
set
{
if (descript == null || !descript.Equals(value))
{
descript = value;
RaisePropertyChanged("Description");
}
}
}
internal ObservableCollection<ArticleLocation> Locations { get => locations; set => locations = value; }
internal ArticleLocation SelectedLocation { get => selectedLocation; set => selectedLocation = value; }
}
我需要像这样显示存储的位置:
class ArticleLocation : INotifyPropertyChanged
{
private string location;
private double available;
public string Location { get => location; set => location = value; }
public double Available { get => available; set => available = value; }
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
}
我现在所拥有的combobox:
<telerik:RadComboBox ItemsSource="{Binding Locations}" DisplayMemberPath="Location" SelectedItem="{Binding SelectedLocation}" SelectionChanged="RadComboBox_SelectionChanged"/>
我不知道如何让位置显示,以便它可以被选择。我能想到的唯一替代方案是将位置名称和可用项保存在单独的列表中……
这并不是说它应该有很大的不同,但我使用的是wpf形式的telerik对象。
发布于 2019-01-23 13:26:38
我发现了问题,由于ArticleLocation类不是公共的,Locations和SelectedLocation属性被创建为内部属性,因此不能被XAML视图访问。
将ArticleLocation类更改为public,并将我的文章类中的属性更改为public,它们开始显示在comobox中。
发布于 2019-01-18 13:51:01
文章类:
public class Article : INotifyPropertyChanged
{
public ObservableCollection<ArticleLocation> locations;
public string Location {
get => location;
set
{
if (location == null || !location.Equals(value))
{
location = value;
RaisePropertyChanged("Location");
}
}
}
}
ArticleLocation类:
public class ArticleLocation : INotifyPropertyChanged
{
private string location;
public string Location {
get => location;
set
{
if (location == null || !location.Equals(value))
{
location = value;
RaisePropertyChanged("Location");
}
}
}
}
在您的xaml.cs类中:
public MainWindow()
{
InitializeComponent();
Article article = new Article();
this.DataContext = article;
}
https://stackoverflow.com/questions/54233872
复制相似问题