XAML ListView:GroupHeaderTemplate binding not working on Release

I have below class:

    public class TitlePropertyViewModel : BaseViewModel
    {
        private int _propertyId;
        private string _name;
        private bool _isRequired;
        private bool _isChecked;
        private bool _answerIsChecked;

        public string GroupingParameter { get; set; }
        public int PropertyId { get => _propertyId; set { _propertyId = value; OnPropertyChanged(); } }
        public string Name { get => _name; set { _name = value; OnPropertyChanged(); } }
        public bool IsChecked { get => _isChecked; set { _isChecked = value; OnPropertyChanged(); } }
        public bool AnswerIsChecked { get => _answerIsChecked; set { _answerIsChecked = value; OnPropertyChanged(); SelectedAnswerChanged?.Invoke(this, new EventArgs()); } }
        public bool IsRequired { get => _isRequired; set { _isRequired = value; OnPropertyChanged(); } }

        public override string ToString() => $"{this.Name}: {(this.IsChecked ? "Checked" : "-")} | {(this.IsRequired ? "Required" : "-")}";
    }

and my properties in View model are:

private IList<TitlePropertyViewModel> _titleProperties;

public IList<TitlePropertyViewModel> TitleProperties { get => _titleProperties; set { _titleProperties = value; OnPropertyChanged(); OnPropertyChanged(nameof(GrouppedTitleProperties)); OnPropertyChanged(nameof(GrouppedFilteredTitleProperties)); } }
public object GrouppedTitleProperties { get => this.TitleProperties?.GroupBy(g => g.GroupingParameter); }
public object GrouppedFilteredTitleProperties { get => this.TitleProperties?.Where(w => w.IsChecked || w.IsRequired).GroupBy(g => g.GroupingParameter); }

I add data in TitleProperties and bind it in my ListView like this:

   <ListView
                ItemsSource="{Binding GrouppedFilteredTitleProperties}"
                IsPullToRefreshEnabled="False"
                IsRefreshing="{Binding IsBusy}"
                IsGroupingEnabled="True"
                HasUnevenRows="True"
                SeparatorVisibility="None"
                CachingStrategy="RecycleElement"
                BackgroundColor="Transparent"
                ItemSelected="Item_Selected"
                >
                <ListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Padding="25,15" BackgroundColor="{DynamicResource PrimaryColor}">
                                <Label Text="{Binding Key}" FontAttributes="Bold" FontSize="Large" 
                                       HorizontalOptions="Start" 
                                       VerticalOptions="Center"
                                       TextColor="{DynamicResource TextColorLight}" />
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.GroupHeaderTemplate>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal" Margin="25,5">
                                <renderer:IconView WidthRequest="25" Source="{Binding IsChecked,Converter={StaticResource PositiveIconConverter}}" FillColor="{Binding IsChecked,Converter={StaticResource PositiveColorConverter}}" VerticalOptions="CenterAndExpand" />
                                <Label Text="{Binding Name}" TextColor="{DynamicResource TextColorLight}"/>
                                <Image Source="exclamation_sign.png" IsVisible="{Binding IsRequired}" VerticalOptions="CenterAndExpand" />
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

This is working on debug mode but when I set the release mode, it doesn't display Key in GroupHeaderTemplate both iOS and Android. But when I set static text on label it work.

This is debug mode:

This is release mode:

Best Answer

  • sumeyyaararsumeyyaarar US ✭✭
    Accepted Answer

    Ok, I found a solution. When I use lambda expression like this:

        public object GrouppedTitleProperties { get => this.TitleProperties?.GroupBy(g => g.GroupingParameter); }
    

    It doesn't work. But when I replace it with the query expression like this:

        public object GrouppedTitleProperties
            {
                get => from tp in this.TitleProperties
                       group tp by tp.GroupingParameter into GrouppedTitleProperties
                       select new
                       {
                           Key = GrouppedTitleProperties.Key,
                           Items = GrouppedTitleProperties.ToList()
                       };
            }
    

    It works. I read this(https://bugzilla.xamarin.com/show_bug.cgi?id=56250) bug report on bugzilla. One of the comments stated that:

    the linker might be stripping the System.Linq or another SDK assembly
    which is breaking the use of the lambda expression.

    So, my problem got solved.

Answers

  • sumeyyaararsumeyyaarar USMember ✭✭
    Accepted Answer

    Ok, I found a solution. When I use lambda expression like this:

        public object GrouppedTitleProperties { get => this.TitleProperties?.GroupBy(g => g.GroupingParameter); }
    

    It doesn't work. But when I replace it with the query expression like this:

        public object GrouppedTitleProperties
            {
                get => from tp in this.TitleProperties
                       group tp by tp.GroupingParameter into GrouppedTitleProperties
                       select new
                       {
                           Key = GrouppedTitleProperties.Key,
                           Items = GrouppedTitleProperties.ToList()
                       };
            }
    

    It works. I read this(https://bugzilla.xamarin.com/show_bug.cgi?id=56250) bug report on bugzilla. One of the comments stated that:

    the linker might be stripping the System.Linq or another SDK assembly
    which is breaking the use of the lambda expression.

    So, my problem got solved.

Sign In or Register to comment.