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

Lack of validation for XAML Style BasedOn & TargetType properties #2476

Open
mrlacey opened this issue May 19, 2020 · 5 comments
Open

Lack of validation for XAML Style BasedOn & TargetType properties #2476

mrlacey opened this issue May 19, 2020 · 5 comments
Labels
area-Designer area-Tooling bug Something isn't working needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) team-Markup Issue for the Markup team

Comments

@mrlacey
Copy link
Contributor

mrlacey commented May 19, 2020

Describe the bug

There is no validation (in the designer/language service or at compile time) to confirm that a style is based on an appropriate type.
Without this check developers do not know what is wrong until running the app and experiencing a XamlParseException with very limited details.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Create a new, blank app
  2. Add the following to MainPage.xaml
<Page.Resources>
        <Style
            x:Key="MyTextBlockStyle"
            BasedOn="{StaticResource MyButtonStyle}"
            TargetType="TextBlock">
            <Setter Property="Foreground" Value="Red" />
        </Style>
        <Style x:Key="MyButtonStyle" TargetType="Button">
            <Setter Property="Background" Value="Aqua" />
        </Style>
    </Page.Resources>
    <Grid>
        <TextBlock Style="{StaticResource MyTextBlockStyle}" />
    </Grid>
  1. Run the app.
  2. See it crash.

Expected behavior

  • The designer/error list should highlight the error.
  • Build should fail because of the invalid style inheritance.

Screenshots

Version Info

NuGet package version:

This is a WinUI3 issue relating to code that's not public (yet?)
It is tied to the XAML language service as used within VS, not the shipping libraries

Windows 10 version Saw the problem?
Insider Build (xxxxx) Yes/No?
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Mobile
Xbox
Surface Hub
IoT

Additional context
This was originally reported to the XAML team but they claim it is not their issue.

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label May 19, 2020
@ranjeshj ranjeshj added team-Markup Issue for the Markup team needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) labels May 19, 2020
@stevenbrix
Copy link
Contributor

@mrlacey can you confirm if this issue repros in WinUI2.x? It sounds like from your issue this is WinUI3.0 only, but I just want to confirm.

@stevenbrix stevenbrix added needs-author-feedback Asked author to supply more information. product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Nov 18, 2020
@mrlacey
Copy link
Contributor Author

mrlacey commented Nov 19, 2020

@stevenbrix Yes, the initial repro was for UWP (WinUI 2)

With WinUI3 (preview 3), the same exception is still thrown but a better error message is included:
Can only base on a Style with target type that is base type of this style's target type.

Ideally it would still be better to see this issue at compile or design time.

@ghost ghost added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. labels Nov 19, 2020
@stevenbrix stevenbrix removed needs-triage Issue needs to be triaged by the area owners product-winui3 WinUI 3 issues labels Nov 19, 2020
@stevenbrix
Copy link
Contributor

Thanks @mrlacey. I agree that the designer should provide a better error message here. Thanks for reporting this!

@RealTommyKlein for FYI - it looks like we are missing some test cases here.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@mrlacey
Copy link
Contributor Author

mrlacey commented Jul 29, 2023

keep open

@duncanmacmichael duncanmacmichael added the bug Something isn't working label Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Designer area-Tooling bug Something isn't working needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

5 participants