BUG: Grouped List picking up wrong Template

ChaseFlorellChaseFlorell CAInsider, University mod

I'm pretty sure this is a bug. I have a grouped list, and sometimes the ItemTemplate applies the background colour of the GroupHeaderTemplate.

Here's my page

<?xml version="1.0" encoding="utf-8"?>

<ContentPage
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:converters="clr-namespace:FutureState.AppCore.ValueConverters;assembly=FutureState.AppCore"
    x:Class="FutureState.AppCore.Pages.MainMenu"
    Title="Breathing Room">

  <ContentPage.Resources>
    <ResourceDictionary>
      <converters:UppercaseValueConverter x:Key="UppercaseValueConverter"></converters:UppercaseValueConverter>
    </ResourceDictionary>
  </ContentPage.Resources>

  <StackLayout Orientation="Vertical">
        <ListView
            x:Name="ModuleList"
            x:FieldModifier="public"
            ItemsSource="{Binding NavigationSections}"
            IsGroupingEnabled="True"
            GroupDisplayBinding="SectionName" >
          <ListView.GroupHeaderTemplate>
            <DataTemplate>
              <ViewCell>
                <StackLayout Orientation="Vertical" BackgroundColor="Teal" Padding="10">
                  <Label Text="{Binding SectionName, Converter={StaticResource UppercaseValueConverter}}" TextColor="White" />
                </StackLayout>
              </ViewCell>
            </DataTemplate>
          </ListView.GroupHeaderTemplate>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout Orientation="Vertical">
                                <Label Text="{Binding Title}" />
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>

And Here's my ViewModel

public class NavigationViewModel : ViewModelBase
{
    private IList<ModulePageViewModel> _modules;
    private UserViewModel _user;
    public IList<NavigationSection> NavigationSections { get; private set; }

    public NavigationViewModel()
    {
        NavigationSections = new List<NavigationSection>();
    }

    public IList<ModulePageViewModel> Modules
    {
        get { return _modules; }
        set
        {
            _modules = value;
            var moduleSection = new NavigationSection("Modules");
            foreach (var item in Modules)
            {
                moduleSection.Add(new NavigationItem { Title = item.Title, Item = item });
            }
            NavigationSections.Add(moduleSection);
        }
    }

    public UserViewModel User
    {
        get { return _user; }
        set
        {
            _user = value;
            var settingsSection = new NavigationSection("Settings & More");
            settingsSection.Add(new NavigationItem { Title = value.FirstName, Item = value });
            settingsSection.Add(new NavigationItem { Title = "Resources", Item = null });
            settingsSection.Add(new NavigationItem { Title = "Terms of Use / Privacy Policy", Item = null });
            settingsSection.Add(new NavigationItem { Title = "About CINIM", Item = null });
            settingsSection.Add(new NavigationItem { Title = "Credits", Item = null });
            NavigationSections.Add(settingsSection);
        }
    }
}

public class NavigationSection : ObservableCollection<NavigationItem>
{
    public string SectionName { get; private set; }

    public NavigationSection(string sectionName)
    {
        SectionName = sectionName;
    }
}

public class NavigationItem
{
    public string Title { get; set; }
    public object Item { get; set; }
}

Posts

  • ChaseFlorellChaseFlorell CAInsider, University mod

    This bug does seem to disappear when I use a TextCell instead of a ViewCell.

          <TextCell Text="{Binding Title}"/>
          <!--<ViewCell>
            <ViewCell.View>
              <StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand">
                <ctrl:FontAwesome Text="{Binding Icon}" VerticalOptions="CenterAndExpand" />
                <Label Text="{Binding Title}" VerticalOptions="CenterAndExpand" />
              </StackLayout>
            </ViewCell.View>
          </ViewCell>-->
    

    Unfortunately, I do need the ability to use a ViewCell

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    I encountered the same bug today. I fixed it by explicitly giving the ItemTemplate a background color.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    Weird, yeah that "appears" to solve it.. must test further.

Sign In or Register to comment.