Developer technologies | .NET | .NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a Syncfusion popup and a collection View inside Everything works as expected, the image, name, price, description, but the button doesn't want to open the picker VM
namespace Scan2Cart.ViewModels;
public partial class HomePageViewModel(IPageService pageService, IDataProvider dataProvider) : BaseViewModel(pageService) {
private bool _isPopupOpening;
[ObservableProperty]
public partial bool IsSelectedQtyPopopOpened { get; set; }
[RelayCommand]
private async Task BarcodesDetected(IEnumerable<BarcodeResult> results) {
if (_isPopupOpening) return; // prevent multiple triggers
var val = results.FirstOrDefault()?.Value;
if (string.IsNullOrEmpty(val))
return;
_isPopupOpening = true;
Product = await dataProvider.GetProductByIdAsync(val);
await Task.Delay(100);
IsProductInfoVisible = true;
IsPopUpDetectedOpen = true;
_isPopupOpening = false;
}
[RelayCommand]
void Yes() {
// Add product if not already in the list
if (!Products.Any(x => x.Id == Product.Id))
Products.Add(Product);
// Close popup and reset flags
IsPopUpDetectedOpen = false;
ShouldDetect = true;
}
[RelayCommand]
void No() {
IsPopUpDetectedOpen = false;
ShouldDetect = true;
}
[RelayCommand]
void Open() {
ShouldDetect = false;
}
[RelayCommand]
void Close() {
IsProductInfoVisible = false;
IsPopUpDetectedOpen = false;
ShouldDetect = true;
}
[RelayCommand]
async Task ShowCart() {
ShouldDetect = false;
IsCartPopopOpen = true;
}
[RelayCommand]
void OenQuantityPopUp() {
IsSelectedQtyPopopOpened = true;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<syncfusion:SfPopup
x:Class="Scan2Cart.Views.PopUps.CartPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:Scan2Cart.Controls"
xmlns:model="clr-namespace:Scan2Cart.Models"
xmlns:picker="clr-namespace:Syncfusion.Maui.Picker;assembly=Syncfusion.Maui.Picker"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.Popup;assembly=Syncfusion.Maui.Popup"
xmlns:vm="clr-namespace:Scan2Cart.ViewModels"
Padding="20"
x:DataType="vm:HomePageViewModel"
AnimationMode="Zoom"
IsFullScreen="True"
ShowCloseButton="True"
ShowHeader="False"
StaysOpen="True">
<syncfusion:SfPopup.ContentTemplate>
<DataTemplate>
<VerticalStackLayout Padding="10" Spacing="5">
<Label FontSize="Large" Text="Your cart" />
<CollectionView ItemsSource="{x:Binding Products}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Product">
<Border>
<Grid
Padding="2"
ColumnDefinitions="60,*,70"
ColumnSpacing="5">
<Image
HeightRequest="60"
HorizontalOptions="Start"
Source="{x:Binding ImageUrl}"
WidthRequest="60" />
<VerticalStackLayout Grid.Column="1">
<Label
FontAttributes="Bold"
FontSize="10"
Text="{x:Binding Name}" />
<Label FontSize="10" Text="{x:Binding Description}" />
<Label
Margin="0,10,0,0"
FontAttributes="Bold"
Text="{x:Binding Price}" />
</VerticalStackLayout>
<Button
Grid.Column="2"
BackgroundColor="Transparent"
Command="{Binding Source={x:Reference CartPage}, Path=BindingContext.OpenQuantityPopUpCommand}"
FontAttributes="Bold"
FontSize="14"
Text="{x:Binding SelectedQuantity}"
TextColor="{x:AppThemeBinding Dark={x:StaticResource White},
Light={x:StaticResource Black}}" />
</Grid>
<Border.StrokeShape>
<RoundRectangle CornerRadius="8" />
</Border.StrokeShape>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<picker:SfPicker
IsOpen="{x:Binding IsSelectedQtyPopopOpened}"
Mode="Dialog"
TextDisplayMode="FadeAndShrink">
<picker:SfPicker.Columns>
<picker:PickerColumn
HeaderText="Select quantity"
ItemsSource="{x:Binding Product.QuantityRange}"
SelectedItem="{x:Binding Product.SelectedQuantity}" />
</picker:SfPicker.Columns>
</picker:SfPicker>
</VerticalStackLayout>
</DataTemplate>
</syncfusion:SfPopup.ContentTemplate>
<syncfusion:SfPopup.PopupStyle>
<syncfusion:PopupStyle
CornerRadius="0"
HasShadow="True"
HeaderBackground="{x:AppThemeBinding Dark='#C8000000',
Light='#00000'}"
MessageBackground="{x:AppThemeBinding Dark='#C8000000',
Light='#C6626161'}" />
</syncfusion:SfPopup.PopupStyle>
</syncfusion:SfPopup>