CollectionView working in debug but not in release in .NET MAUI - xaml

I have the following
<CollectionView Margin="5" ItemsSource="{Binding Subjects}">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="2" />
</CollectionView.ItemsLayout>
<CollectionView.EmptyView>
<ContentView>
<Label Text="No subjects entered yet..." />
</ContentView>
</CollectionView.EmptyView>
<CollectionView.ItemTemplate>
<DataTemplate>
<Border MaximumWidthRequest="300">
<Border.StrokeShape>
<RoundRectangle CornerRadius="10" />
</Border.StrokeShape>
<Border.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type vm:MainPageViewModel}}, Path=DeleteSubjectCommand}" CommandParameter="{Binding .}" />
</Border.GestureRecognizers>
<Label Margin="5" Text="{Binding .}" />
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
The problem is that the <Label Margin="5" Text="{Binding .}" /> is blank in release in my .NET MAUI Android application while in debug, it is populated and the gesture recogniser works.
When I add items to the list, the correct number of items appears so it leads me to think that there is something happening with the label highlighted above.
How do I solve this?

Replace:
<DataTemplate>
With:
<DataTemplate x:DataType="{x:Type x:String}>
Do not ask me why.

Related

Carousal view with multiple items without databinding

How do I set static text as Carousal view items instead of doing data binding? Here in the below code I am trying to have Page 2 appear when the user swipes to the left. This code says The property ItemTemplate is set more than once
<StackLayout Margin="10">
<CarouselView>
<CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Label Text="Page 1"/>
</Grid>
</DataTemplate>
</CarouselView.ItemTemplate>
<CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Label Text="Page 2"/>
</Grid>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</StackLayout>
If you want to set the items statically in xaml itself without data binding you can use Array markup extension of type string:
<StackLayout Margin="10">
<CarouselView>
<CarouselView.ItemsSource>
<x:Array Type="{x:Type sys:String}">
<sys:String>Page 1</sys:String>
<sys:String>Page 2</sys:String>
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Label Text="{Binding .}" />
</Grid>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</StackLayout>
PS: Don't forget to add the required xaml namespace:
xmlns:sys="clr-namespace:System;assembly=mscorlib"

Xamarin Forms ignore Button binding from DataType on StackLayout

I have got the following xaml code:
<StackLayout Padding="10" x:DataType="model:Light">
<StackLayout HorizontalOptions="FillAndExpand" Grid.Column="0" Grid.Row="1">
<Label Text="{Binding Name}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="24" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand"/>
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand" Grid.Column="1" Grid.Row="1" >
<Button Text="{Binding Enabled}" Command="{Binding ToggleLight}" CommandParameter="{Binding .}" HorizontalOptions="CenterAndExpand"></Button>
</StackLayout>
</StackLayout>
How do I exclude Command="{Binding ToggleLight}" on my Button form the x:DataType="model:Light" defined on my StackLayout?
Use binding-path.
Define "x:Name" outside the StackLayout (StackLayout, Grid, ListView and etc.)
Add "x:Reference" for your Command binding inside the StackLayout
The command is excluded.
Like:
<Grid x:Name="WhateverParent">
<StackLayout x:DataType="model:Light">
<Button ... Command="{Binding Path=BindingContext.ToggleLight, Source={x:Reference WhateverParent}}" />
</StackLayout>
</Grid>

Xamarin XAML file wont change after changing some code

In my XAML File after changing some code inside it and then debug on my phone, the changes I made do not reflect on my phone. It keep showing my old code.
Old code :
<ListView
ItemsSource="{Binding Allgroups}"
RowHeight="75"
IsGroupingEnabled="true">
<ListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding NameNative}"></Label>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding TitleWithItemCount}" />
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
</ListView>
new code :
<Label Text="HELOO WORLD "></Label>
I Noticed every time i run the code , it keep showing the list.I have to click the save button then the list disappear and hello world appear .
I reset VS settings and relaunched it .
worked for me
<CollectionView ItemsSource="{Binding Categoriesxx}" IsGrouped="True">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="1" VerticalItemSpacing="5" HorizontalItemSpacing="5"></GridItemsLayout>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout >
<Label Text="{Binding NameNative}"></Label>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.GroupHeaderTemplate>
<DataTemplate>
<StackLayout BackgroundColor="AliceBlue">
<Label Text="{Binding Name}" FontSize="Title"></Label>
<Button Image="{Binding StateIcon}"
BackgroundColor="Transparent"
BorderColor="Transparent"
BorderWidth="0"
Command="{Binding BindingContext.ExpandCommand ,Source={x:Reference ServiceListPage}}"/>
</StackLayout>
</DataTemplate>
</CollectionView.GroupHeaderTemplate>
</CollectionView>

Get SelectedItem from a nested RepeaterView

I am using DottorPagliaccius repeater view thats nested inside another repeaterview. The command RSSFeedSelectedCommand doesnt work unless on top repeater, which in theory makes sense but how can i get it to work?
I have looked into using Converters and bindtoeventcommand but cant see to get them working.
<repeater:RepeaterView x:Name="MainRepeater" SeparatorHeight="25" ItemsSource={Binding Feeds}">
<repeater:RepeaterView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Spacing="10">
<Label Text="{Binding Title}" TextColor="Blue" />
<Label Text="{Binding Description}" TextColor="Red" FontSize="12" />
<repeater:RepeaterView x:Name="MainRepeater2" EmptyText="No elements" ShowSeparator="true" SeparatorHeight="2" SeparatorColor="Silver" ItemsSource="{Binding Items}" SelectedItemCommand="{Binding RSSFeedSelectedCommand}">
<repeater`enter code here`:RepeaterView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Image Source="{Binding Image.Url}"></Image>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Title}" TextColor="Black" />
<Label Text="{Binding Description}" TextColor="Black" FontSize="12" />
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</repeater:RepeaterView.ItemTemplate>
</repeater:RepeaterView>
</StackLayout>
</ViewCell>
</DataTemplate>
</repeater:RepeaterView.ItemTemplate>
</repeater:RepeaterView>
The Repeater was trying to find the command in Feeds however exists in the ViewModel.
<repeater:RepeaterView x:Name="MainRepeater2" EmptyText="No elements" ShowSeparator="true" SeparatorHeight="2" SeparatorColor="Silver" ItemsSource="{Binding Items}" SelectedItemCommand="{Binding Source={x:Reference RSSPage}, Path=BindingContext.RSSFeedSelectedCommand}">
and you have to name the page:
<ContentPage x:Name="PageName" />
If my assumption is correct, your class structure should be something like,
ViewModel
|__List of Feeds
|__List of Items
|__RSSFeedSelectedCommand
So, DataContext of your inner repeater control (MainRepeater2) will be Feed. So, try with DataContext of outer repeater control. Like,
<repeater:RepeaterView x:Name="MainRepeater2" ItemsSource="{Binding Items}"
SelectedItemCommand="{Binding DataContext.RSSFeedSelectedCommand,
ElementName=MainRepeater}"/>
For Xamarin:
<repeater:RepeaterView x:Name="MainRepeater2" ItemsSource="{Binding Items}"
SelectedItemCommand="{Binding DataContext.RSSFeedSelectedCommand,
Source={x:Reference MainRepeater}}"/>

Xamarin forms listview context action doesn't work with details

I use XF listview with menu context action and viewcell selected by tap.
The context actions don't work when I implemented TapGestureReconizer.
My code is here:
<ListView x:Name="PaymentCardsListView"
CachingStrategy="RecycleElement"
ItemsSource="{Binding PaymentCardsList}"
SelectedItem="{Binding SelectedPaymentCard, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Command="{Binding Path=BindingContext.EditCommand, Source={x:Reference PaymentCardsListView}"
CommandParameter="{Binding .}"
Text="Edit"/>
<MenuItem Command="{Binding Path=BindingContext.DeleteCommand, Source={x:Reference PaymentCardsListView}"
CommandParameter="{Binding .}"
IsDestructive="true"
Text="Delete"/>
</ViewCell.ContextActions>
<StackLayout Orientation="Horizontal">
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Path=BindingContext.DetailCommand, Source={x:Reference PaymentCardsListView}"
CommandParameter="{Binding .}"/>
</StackLayout.GestureRecognizers>
<StackLayout Orientation="Vertical">
<Label Text="{Binding Name}"/>
<Label Text="{Binding Number}"/>
<StackLayout Orientation="Horizontal">
<Label Text="Expiry Date: "/>
<Label Text="{Binding ExpMonth}"/>
<Label Text="/"/>
<Label Text="{Binding ExpYear}"/>
</StackLayout>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I need to work with context menu and stacklayout tap.
How should I implement this?
It works on iOS.
The issue is only on Android.
I found confirmed bug on bugzilla.
https://bugzilla.xamarin.com/show_bug.cgi?id=46363
I'm thinking about walkthrough.
One of them it create custom renderer for view cell for android and override LongPress for display custom menu.