Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICommand and other Inteface differences bewteen UWP and WinUI #10

Open
GuildOfCalamity opened this issue Aug 28, 2021 · 19 comments
Open
Assignees

Comments

@GuildOfCalamity
Copy link

GuildOfCalamity commented Aug 28, 2021

I was wondering if anyone else was trying this:

I was going to see how far I could get in the book by using the built-in blank UWP template in VS2019.

When setting up a blank UWP project, it seems some of the interfaces aren't compatible.

Specifically the ICommand interface in the RelayCommand class.

I've changed "using Microsoft.UI.Xaml.Input;" to "using System.Windows.Input;" to see if that will work.

Same thing with the Microsoft.UI.Xaml.Interop.NotifyCollectionChangedAction, but I cannot find a replacement besides using System.Collections.Specialized

Is anyone else trying these projects using standard UWP, or is it impossible because of these specialized interfaces and the WinUI library?

@jvsca if you're out there, did you ever make it past chapter 4?

@jvsca
Copy link

jvsca commented Aug 29, 2021

@GuildOfCalamity Yes, in Chapter 4 was when I almost quit reading the book because the project will not compile anymore (and the project templates in the book did not match the ones on VS 2019, and the same with the NuGet packages). Then the same issue in another Chapter. At the end I finished the book with all the code working.
I will put the code in Github maybe tomorrow.

@GuildOfCalamity
Copy link
Author

GuildOfCalamity commented Aug 29, 2021

@jvsca That would be great if you could! I made it pretty far using the Nugets you recommended but the Interfaces are killing me.

You bring up a good point about the templates. I'm hoping Alvin will update all the source code and branch it to represent the changes that have occurred with WinUI, a.k.a. Project Reunion, a.k.a. WindowsAppSDK.

@jvsca
Copy link

jvsca commented Aug 29, 2021

@GuildOfCalamity https://github.com/jvsca/MyMediaCollection

@GuildOfCalamity
Copy link
Author

GuildOfCalamity commented Aug 29, 2021

@jvsca Thanks! I found that I could only get yours to build after adding the suggested references...
WinUI_References

I'm not sure what your references normally look like, this maybe just a difference with our respective local Nuget caches.

@jvsca
Copy link

jvsca commented Aug 29, 2021

@GuildOfCalamity I always clean the solution. The reference are almost the same:
image

@GuildOfCalamity
Copy link
Author

No worries, I was just surprised when I opened it to see that familiar ICommand error...
ICommand

@alvinashcraft
Copy link
Collaborator

Thanks for all the feedback, folks. I know it's difficult to work with this stuff when it keeps changing. I think I will create a branch once the Windows App SDK 1.0 release is out (hopefully that is very soon!).

With the recent news about UWP not coming to .NET 5/6, what do you all think I should do about the WinUI in UWP projects in the new branch? Should they get switched to WinUI Desktop projects, so they'll all work with the v1 SDK?

@alvinashcraft alvinashcraft self-assigned this Oct 22, 2021
@GuildOfCalamity
Copy link
Author

GuildOfCalamity commented Oct 22, 2021

Thanks for all the feedback, folks. I know it's difficult to work with this stuff when it keeps changing. I think I will create a branch once the Windows App SDK 1.0 release is out (hopefully that is very soon!).

With the recent news about UWP not coming to .NET 5/6, what do you all think I should do about the WinUI in UWP projects in the new branch? Should they get switched to WinUI Desktop projects, so they'll all work with the v1 SDK?

Thanks Alvin!
Would love to see a new branch will all updated solutions.
I guess it would make sense to switch to the WinUI Desktop. I would only ask that you include a readme that explains the proper Nugets and their names (since this caused so much confusion last time, not your fault).

@jvsca
Copy link

jvsca commented Oct 22, 2021

Thanks for all the feedback, folks. I know it's difficult to work with this stuff when it keeps changing. I think I will create a branch once the Windows App SDK 1.0 release is out (hopefully that is very soon!).

With the recent news about UWP not coming to .NET 5/6, what do you all think I should do about the WinUI in UWP projects in the new branch? Should they get switched to WinUI Desktop projects, so they'll all work with the v1 SDK?

Thanks Alvin.
Please update the solutions.
I almost quit reading the book two times because the code will not compile. At the end I finish the book with all the code working (after many changes).

@GuildOfCalamity
Copy link
Author

GuildOfCalamity commented Oct 22, 2021

@jvsca I had to stop reading the book and trying the samples because nothing worked (I can't believe you stuck with it until the end, bravo!). I've been trying to just use the default UWP packages and following the samples on Microsoft's github.

@theRaak
Copy link

theRaak commented Dec 27, 2021

I'm going through the book trying the progressive samples as a .NET 6 WinUI Desktop project. Stuck at the beginning of Ch. 4 with a 'ViewModel property cannot be null' runtime hang up.

@alvinashcraft
Copy link
Collaborator

I'm going through the book trying the progressive samples as a .NET 6 WinUI Desktop project. Stuck at the beginning of Ch. 4 with a 'ViewModel property cannot be null' runtime hang up.

Do you know from the error which property is having an issue? I haven't seen that kind of error before. Usually nulls are handled by xaml unless there's a custom converter that isn't checking for null. Can you modify the getter of the property to return another non-null default value when it is null?

@theRaak
Copy link

theRaak commented Dec 27, 2021

Here's the line it stalls on:
public MainViewModel ViewModel { get; } = (Application.Current as App).Container.GetService();
I'll try modifying the getter.
Thanks.

@theRaak
Copy link

theRaak commented Dec 27, 2021

(Application.Current as App).Container = null
Above property being null throws the following:
System.ArgumentNullException: 'Value cannot be null. (Parameter 'provider')'

@alvinashcraft
Copy link
Collaborator

Is the code to initialize the Container in App.xaml.cs in place? Make sure The RegisterServices() method is there, and it's being called what the app is launched. In the example code, it's called at the beginning of App.OnLaunched().

@theRaak
Copy link

theRaak commented Dec 27, 2021

Brilliant! Moved 'Container = RegisterServices();' to the beginning of OnLaunched, before the MainWindow activates. We're back in business now.

Thanks for the prompt response, Alvin. Happy New Year.

@alvinashcraft
Copy link
Collaborator

That's great! I'm happy to hear that resolved the problem. Good luck with the rest and happy new year to you too!

@theRaak
Copy link

theRaak commented Jan 4, 2022

While working through Ch04, found the following issue with NavigationService.cs:

Line 19 - private static Frame AppFrame => (Frame)Window.Current.Content;

(Frame)Window.Current = null
throws "System.NullReferenceException: 'Object reference not set to an instance of an object.'"

@alvinashcraft
Copy link
Collaborator

It looks like there are some differences here between the UWP and Desktop WinUI projects. Take a look at this discussion about making this call on a UI thread in a desktop project. microsoft/microsoft-ui-xaml#2609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants