Мне не удалось выполнить группировку в виде списка. Он показывает код ошибки как:
BindingExpression path error: Indicator' property not found on 'object' ''CollectionViewGroupInternal'`.
могу я узнать, какая часть моего кода неверна?
Ниже приведен код класса:
Данные берутся из базы данных.
foreach(string value in getCountry)
{
string[] values = value.Split(',');
string countryname = values[0].ToString();
string indicator = values[1].ToString();
items.Add(new User() { CountryName = countryname, Indicator = indicator });
}
lvUsers.ItemsSource = items;
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(lvUsers.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("Indicator"); //i expect error is from here
view.GroupDescriptions.Add(groupDescription);
public class User
{
public string CountryName { get; set; }
public string Indicator { get; set; }
}
Ниже представлен КОД XAML:
<ListView Name = "lvUsers" FontSize = "25" FontFamily = "Arial">
<ListView.View>
<GridView ColumnHeaderContainerStyle = "{StaticResource myHeaderStyle}">
<GridViewColumn DisplayMemberBinding = "{Binding CountryName}" />
<GridViewColumn DisplayMemberBinding = "{Binding Indicator}" />
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontWeight = "Bold" Text = "{Binding Indicator}" FontSize = "30" FontFamily = "Arial" Foreground = "Black"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>





В HeaderTemplate свойство связывания должно быть Name, а не Indicator.
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontWeight = "Bold" Text = "{Binding Name}" FontSize = "30" FontFamily = "Arial" Foreground = "Black"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
Свойство Name происходит из класса CollectionViewGroup, который является родительским для CollectionViewGroupInternal. Группа Users обернута как CollectionViewGroupInternal, так что свойство связывания должно исходить от CollectionViewGroupInternal, а не от User.
Принято к сведению! Спасибо за объяснение ! Я думал, что свойство Name является обязательным значением.
Привет, в классе пользователя нет имени