-
Notifications
You must be signed in to change notification settings - Fork 487
Closed
Labels
area/viewsIssue/Discussion/PR that has to do with ViewsIssue/Discussion/PR that has to do with ViewsbugSomething isn't workingSomething isn't workingunverified
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
Issue
When displaying a popup using IPopupService.ShowPopup (or ...Async, doesn't matter), the popup is displayed empty (you can't see anything, but the main page becomes disabled and becomes enabled again after you click on it anywhere.
For example (based on the default MAUI program template in VS 2022):
MyPopup.xaml
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp2"
Color="Transparent"
x:Class="MauiApp2.MyPopup">
<VerticalStackLayout>
<CollectionView ItemsSource="{Binding Messages}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</toolkit:Popup>
MyPopup.xaml.cs
public partial class MyPopup : Popup
{
public MyPopup(MyPopupViewmodel viewmodel)
{
BindingContext = viewmodel;
InitializeComponent();
}
}
MyPopupViewmodel.cs
public class MyPopupViewmodel : INotifyPropertyChanged
{
private ObservableCollection<string>? _messages;
public event PropertyChangedEventHandler? PropertyChanged;
public ObservableCollection<string>? Messages
{
get => _messages;
set
{
_messages = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Messages)));
}
}
}
MainPage.xaml.cs
private void OnButtonClicked(object sender, EventArgs e)
{
_popupService.ShowPopup<MyPopupViewmodel>(viewmodel => viewmodel.Messages = new System.Collections.ObjectModel.ObservableCollection<string>(new[] { "Hello, World!" }));
}
Additional information
- Setting the messages in the popup's constructor and using
ShowPopupwithout usingonPresentingresolves the issue e.g.,
public MyPopup(MyPopupViewmodel viewmodel)
{
BindingContext = viewmodel;
viewmodel.Messages = new System.Collections.ObjectModel.ObservableCollection<string>
{
"Hello world",
};
InitializeComponent();
}
- Alternativoodooly, playing around with
MinimumWidthRequestandMinimumHeightRequestproperties on theStackLayoutin the popup to any value larger than 1 also resolves the issue andShowPopupcan be used with setting the content inonPresenting.
### Expected Behavior
The popup should display correctly when using `ShowPopup` with `onPresenting`.
### Steps To Reproduce
1. Create a new MAUI program using the default template in VS 2022.
2. Add the MAUI CommunityToolkit and a popup as described in this post.
### Link to public reproduction project repository
https://github.com/urielginsburg/maui-communitytoolkit-popup-issue
### Environment
```markdown
- .NET MAUI CommunityToolkit: 9.0.0
- OS: Windows 11
- .NET MAUI: 8.0.41
Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/viewsIssue/Discussion/PR that has to do with ViewsIssue/Discussion/PR that has to do with ViewsbugSomething isn't workingSomething isn't workingunverified
