我试图在Listview中对我的项目进行分组。我想把它们分组为#34; EventId" property并将EventId显示为标题文本。 Groupping工作正常,我的项目被分组,但问题是,所有组的标题文本都是空的。
这是我的xaml:
<ListView
ItemsSource="{Binding CardEvents}"
MinHeight="120"
MaxHeight="120"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Name="CardEventsListView">
<ListView.View>
<GridView>
<GridViewColumn Header="Kart Türü" DisplayMemberBinding="{Binding CardType}" Width="{Binding ActualWidth, ElementName=cardEvent_headerA}"/>
<GridViewColumn Header="Oluşturma Tarihi" DisplayMemberBinding="{Binding EventDateTime, Converter={StaticResource dateTimeConverter}}" Width="{Binding ActualWidth, ElementName=cardEvent_headerB}"/>
<GridViewColumn Header="Event Id" DisplayMemberBinding="{Binding EventId}" Width="{Binding ActualWidth, ElementName=cardEvent_headerC}"/>
<GridViewColumn Header="Dakika" DisplayMemberBinding="{Binding Minute}" Width="{Binding ActualWidth, ElementName=cardEvent_headerD}"/>
<GridViewColumn Header="İşlem Dk" DisplayMemberBinding="{Binding RelativeMinute, Converter={StaticResource ResourceKey=timeSpanConverter}}" Width="{Binding ActualWidth, ElementName=cardEvent_headerE}"/>
<GridViewColumn Header="Op." DisplayMemberBinding="{Binding UserName}" Width="{Binding ActualWidth, ElementName=cardEvent_headerF}"/>
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontSize="14" FontWeight="Bold" Text="{Binding EventId}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
在我的Textblock中,我在哪里进行绑定,我得到警告
无法解析符号&#39; EventId&#39;
我不知道为什么我无法访问EventId属性,而我可以在GridViewColumn中访问它。
答案 0 :(得分:3)
您无法将ItemSource的EventId
绑定到您的论坛的DataTemplate,而是尝试使用Name
<DataTemplate>
<TextBlock FontSize="14" FontWeight="Bold" Text="{Binding Name}" />
</DataTemplate>
此处Name
是组的名称,由WPF分配,但不是从DataModel分配。
参考 - http://www.wpf-tutorial.com/listview-control/listview-grouping/