CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.08k stars 300 forks source link

Adding version 8.2.2 to existing Maui project breaks xaml file(s) #875

Open rkreisel opened 6 months ago

rkreisel commented 6 months ago

Describe the bug

I had a working project using the that was not using the CommunityToolkit.

It built and ran fine. I added the CommunityToolkit

and now the build throws this error: "Input string was not in the correct format" It points to line 1 of the mainpage.xaml file.

Regression

No response

Steps to reproduce

.net 8
Maui project 
VS 2022
Fairly simple app that retrieves information from a web service and formats it on the device.
Ensure it works without the toolkit. 

Add the toolkit and attempt to build.
I get the error noted above.

Add the following to the main page.
<ContentPage
other stuff...
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit">
    <ContentPage.Behaviors>
        <mct:EventToCommandBehavior Command="{Binding AppearingCommand}" EventName="Appearing" />
    </ContentPage.Behaviors>

... other xaml
</ContentPage>

<ContentPage.Behaviors>
        <mct:EventToCommandBehavior Command="{Binding AppearingCommand}" EventName="Appearing" />
    </ContentPage.Behaviors>

Try the build again to get the message telling you to change the startup.

Change the MauiProgram start to include the toolkit:
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            });
        builder.Services.Add... blah blah blah other services
        return builder.Build();
    }

Build again - get an error telling you you need implement the target method in the viewmodel.cs
Implement it per the instructions here: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/behaviors/event-to-command-behavior

Build again and get the original error.

Expected behavior

I was trying to implement loading of the data when the app starts, but cannot get past the xml error. So the expected behavior would have been to load the data when the app started.

Screenshots

No response

IDE and version

VS 2022

IDE version

Version 17.9.6

Nuget packages

Nuget package version(s)

see the bug description above where I pasted in the references

Additional context

I have to caveat this problem with telling you that is is my first Maui app outside of a class. So, I quite possibly am missing something very basic.

Help us help you

Yes, but only if others can assist

rkreisel commented 6 months ago

Hmmm, The stuff I pasted into the bug description area does not seem to have been included. I'll try again.

xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"

PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" /> PackageReference Include="CommunityToolkit.Maui.Core" Version="9.0.0" /> PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> PackageReference Include="Microsoft.Maui.Controls" Version="8.0.21" /> PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.21" /> PackageReference Include="Microsoft.Maui.Essentials" Version="8.0.21" /> PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.5.1" />