xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.
MIT License
1.58k stars 471 forks source link

[Bug] Toast and Snackbar not working in UWP #1308

Open ninaada opened 3 years ago

ninaada commented 3 years ago

Description

Toast and Snackbar are not working in UWP. But, they seem to be working only in the samples repo/app of the toolkit. Attaching a repro of the same.

Steps to Reproduce

Use the zip to download and run the project in Visual Studio

Expected Behavior

Toast should be displayed after 3 seconds with message "Test notification"

Actual Behavior

A System.PlatformNotSupportedException is thrown with message "Operation is not supported in this platform"

Basic Information

Workaround

No known workaround yet

Reproduction Link

TestApp.zip

TomReemer commented 3 years ago

Hi There,

The same here as well. I'm redoing a sample of Gerald Versluis on ToastAsync works just fine on Android, as expected, but on UWP I get a System.PlatformNotSupportedException: 'Operation is not supported on this platform.'

Code-behind: async public void OnButton_ClickMe(object sender, EventArgs args) { await this.DisplayToastAsync("Does it work?", 10000); }

VladislavAntonyuk commented 3 years ago

I will take a look. From the exception I can say that the issue happens because the uwp implementation of the Snackbar is not found. The code is executed from the NetStandard

jfversluis commented 3 years ago

Looks like a problem with the target versions on UWP and the wrong DLL being included when the developer targets the wrong UWP version?

@TomReemer what version are you targeting? Could you try playing with that setting and see if that changes something?

VladislavAntonyuk commented 3 years ago

At least I expect to see "Anchor Not Supported on UWP"

ninaada commented 3 years ago

@jfversluis Maybe, but another interesting thing is that this happens when installed via nuget. If I run the sample in XCT repo, it works. Maybe some kind of dll issue.

AndreiMisiukevich commented 3 years ago

Hi @ninaada UWP: 18362 can you please play with target versions? (try to set the most recent and test if it works)

VladislavAntonyuk commented 3 years ago

for some reason, the Border (https://github.com/xamarin/Xamarin.Forms/blob/b85c28e530eff581c6fa48742e07cd84cca7dd3e/Xamarin.Forms.Platform.UAP/PageControlStyle.xaml#L48) is not found and we are not able to put the Snackbar

FindVisualChildByName<Border>(data, "BottomCommandBarArea") returns null

ninaada commented 3 years ago

@AndreiMisiukevich Tried with 17763 and 19041 as well. Cleaned, uninstalled the app before running. Same issue there also.

VladislavAntonyuk commented 3 years ago

I found the solution, you have to change in App.xaml.cs -> MainPage = new NavigationPage(new MainPage());

image

ninaada commented 3 years ago

@VladislavAntonyuk Tried that, still getting the same exception. image

VladislavAntonyuk commented 3 years ago

To summarize: To make it work right now you need 2 things:

  1. Set min UWP version 19041
  2. Use NavigationPage. MainPage = new NavigationPage(new MainPage()). Probably needs to be added to the documentation.
ninaada commented 3 years ago

Any update on this ?

Luk164 commented 3 years ago

Just occured to me as well. @VladislavAntonyuk I wanted to try out your workaround but I am a but confused. Into which App.xaml.cs is it supposed to go? In my prism template this is how the first view is called NavigationService.NavigateAsync("NavigationPage/LoginPage"); which supposedly wraps it in navigation page by itself yet I still get the error.

VladislavAntonyuk commented 3 years ago

Just occured to me as well. @VladislavAntonyuk I wanted to try out your workaround but I am a but confused. Into which App.xaml.cs is it supposed to go? In my prism template this is how the first view is called NavigationService.NavigateAsync("NavigationPage/LoginPage"); which supposedly wraps it in navigation page by itself yet I still get the error.

It have to be in shared project App.Xaml.cc. Did you remove the nuget package and added the reference to the source code? If you still see the issue, it means that the container for the Snackbar is not found. Could you please share the sample?

Luk164 commented 3 years ago

@VladislavAntonyuk Here is a copy of my project. I barely started so there is no confidential information or proprietary code yet. archived.zip

VladislavAntonyuk commented 3 years ago

@Luk164 if you do what I wrote above, it will work: image

VladislavAntonyuk commented 3 years ago

So

  1. you have to set min version to 19041 image

  2. Make sure you use NavigationPage