I have a GroupHeaderTemplate in Xamarin.Forms for a ListView element which is not rendering. You can select the headers, and pull up the quick menu. I can successfully render the groups if I use the property of the ListView element GroupDisplayBinding, yet when I specify GroupHeaderTemplate property of ListView nothing renders. In both cases my ListView ItemTemplate does not render. If I remove the header, the ItemTemplate renders as expected.
<ResourceDictionary>
<local:DateConverter x:Key="dateConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<ListView x:Name="barGraphListView" ItemsSource="{x:Static local:BarGraphModelColl.bgModelColl}"
IsGroupingEnabled="True"
HasUnevenRows="True" HorizontalOptions="FillAndExpand" VerticalOptions="EndAndExpand">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell Height="25">
<Label Text="{Binding Date, Converter={StaticResource dateConverter}}" TextColor="White" />
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Vertical" Padding="0,10">
<Label Text="{Binding DataCategory}" />
<BoxView WidthRequest="{Binding BarHeight}" HorizontalOptions="Start" Color="Blue" HeightRequest="20" />
</StackLayout>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This is my converter
class DateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo cultureInfo)
{
DateTime dateTime = (DateTime)value;
return String.Format("{0:dddd, MMMM d, yyyy}", dateTime);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo cultureInfo)
{
throw new NotImplementedException();
}
}
You will need to specify your GroupDisplayBinding property on your ListView so it knows what to display and bind to. You will want to probably use my Grouping here and you wouldn't even need to use your converter as it would just be your Key.
http://motzcod.es/post/94643411707/enhancing-xamarin-forms-listview-with-grouping
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments