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

Warning XC0022 if using FormattedText from a Label #20633

Closed
AndreasReitberger opened this issue Feb 16, 2024 · 4 comments · Fixed by #20742
Closed

Warning XC0022 if using FormattedText from a Label #20633

AndreasReitberger opened this issue Feb 16, 2024 · 4 comments · Fixed by #20742

Comments

@AndreasReitberger
Copy link

AndreasReitberger commented Feb 16, 2024

Description

If setting the DataType of the ContentPage and using a Label.FormattedText, the compiler warns XC0022 while using Label.Text does not warn.

            <!-- Does not warn XC0022 -->
            <Label
                Text="{Binding Name}"
                Style="{StaticResource SubHeadline}"
                SemanticProperties.HeadingLevel="Level2"
                SemanticProperties.Description="Welcome to dot net Multi platform App U I" />

            <Label>
                <Label.FormattedText>
                    <FormattedString>
                        <FormattedString.Spans>
                            <!-- Does warn XC0022 -->
                            <Span Text="{Binding Name}"/>
                            <Span Text="!"/>
                        </FormattedString.Spans>
                    </FormattedString>
                </Label.FormattedText>
            </Label>
            <!-- Does not warn XC0022 -->
            <Button
                x:Name="CounterBtn"
                Text="{Binding Name}" 
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                HorizontalOptions="Fill" />

@StephaneDelcroix

Steps to Reproduce

  1. See the repro => https://github.com/AndreasReitberger/WarningXC0022Repro
  2. Build it and see the warnings

Link to public reproduction project repository

https://github.com/AndreasReitberger/WarningXC0022Repro

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

8.0.6 SR1

Affected platforms

iOS, Android, Windows, macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Build started at 07:46...
1>------ Build started: Project: XamlCompiledBinding, Configuration: Debug Any CPU ------
1>MainPage.xaml(38,35): XamlC XC0022 warning : Binding could be compiled if x:DataType is specified.
1>MainPage.xaml(38,35): XamlC XC0022 warning : Binding could be compiled if x:DataType is specified.
1>MainPage.xaml(38,35): XamlC XC0022 warning : Binding could be compiled if x:DataType is specified.
1>XamlCompiledBinding -> C:\Users\andreas\Desktop\Maui\XamlCompiledBinding\XamlCompiledBinding\bin\Debug\net8.0-maccatalyst\maccatalyst-x64\XamlCompiledBinding.dll
1>XamlCompiledBinding -> C:\Users\andreas\Desktop\Maui\XamlCompiledBinding\XamlCompiledBinding\bin\Debug\net8.0-ios\iossimulator-x64\XamlCompiledBinding.dll
1>XamlCompiledBinding -> C:\Users\andreas\Desktop\Maui\XamlCompiledBinding\XamlCompiledBinding\bin\Debug\net8.0-android\XamlCompiledBinding.dll
1>Done building project "XamlCompiledBinding.csproj".
1>MainPage.xaml(38,35): XamlC XC0022 warning : Binding could be compiled if x:DataType is specified.
1>XamlCompiledBinding -> C:\Users\andreas\Desktop\Maui\XamlCompiledBinding\XamlCompiledBinding\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\XamlCompiledBinding.dll
1>Done building project "XamlCompiledBinding.csproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 07:46 and took 15,471 seconds ==========
@AndreasReitberger AndreasReitberger added the t/bug Something isn't working label Feb 16, 2024
@StephaneDelcroix StephaneDelcroix self-assigned this Feb 16, 2024
@AndreasReitberger AndreasReitberger changed the title Warning XC002 if using FormattedText from a Label Warning XC0022 if using FormattedText from a Label Feb 16, 2024
@mattleibow
Copy link
Member

mattleibow commented Feb 20, 2024

Related to #20568

@mattleibow mattleibow marked this as a duplicate of #20568 Feb 20, 2024
@mattleibow
Copy link
Member

This was a new warning added to avoid some common perf and binding issues. The data type should propagate to the spans, but maybe @StephaneDelcroix has more input?

You can disable the warnings for now:

<NoWarn>$(NoWarn);XC0022;XC0023</NoWarn>

@mattleibow mattleibow added this to the Backlog milestone Feb 20, 2024
@ghost
Copy link

ghost commented Feb 20, 2024

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@AndreasReitberger
Copy link
Author

This was a new warning added to avoid some common perf and binding issues. The data type should propagate to the spans, but maybe @StephaneDelcroix has more input?

You can disable the warnings for now:

<NoWarn>$(NoWarn);XC0022;XC0023</NoWarn>

Thanks @mattleibow for your reply.
The issue is not that it warns, the issue is that the mechanism doesn't see the DataType if using the FormatedText property, but it works for Text property.

There is a DataType specified, for the ContentPage. So the FormatedText is using a compiled binding, but it still warns, while it doesn't warn for the Text property. I would expect the same for the FormatedText property. Hope this clarifies it a little bit more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants