Skip to content

Adding Name to a Resource fails on build #1427

Closed

Description

@NGame1

Current behavior

this code is fine:

<UserControl.Resources>
    <LinearGradientBrush x:Key="TurnedOnLightGradiantColor" StartPoint="0,0.5" EndPoint="1,0.5">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="#897de3" Offset="0.5"/>
            <GradientStop Color="#764294" Offset="1"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="TurnedOffLightGradiantColor" StartPoint="0,0.5" EndPoint="1,0.5">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="LightGray" Offset="0.5"/>
            <GradientStop Color="DarkGray" Offset="1"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
</UserControl.Resources>

but if you add a name it will fail

<UserControl.Resources>
    <LinearGradientBrush x:Name="TurnedOnLightGradiantColorName" x:Key="TurnedOnLightGradiantColor" StartPoint="0,0.5" EndPoint="1,0.5">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="#897de3" Offset="0.5"/>
            <GradientStop Color="#764294" Offset="1"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
    <LinearGradientBrush x:Name="TurnedOffLightGradiantColorName" x:Key="TurnedOffLightGradiantColor" StartPoint="0,0.5" EndPoint="1,0.5">
        <LinearGradientBrush.GradientStops>
            <GradientStop Color="LightGray" Offset="0.5"/>
            <GradientStop Color="DarkGray" Offset="1"/>
        </LinearGradientBrush.GradientStops>
    </LinearGradientBrush>
</UserControl.Resources>

The name 'nameScope' does not exist in the current context HomeControlApp.Droid \obj\Debug\80\g\XamlCodeGenerator\LightWidgetUC_9e91f51bbe3d28fd457787006913b69b.g.cs
image

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • Windows
  • Build tasks

Visual Studio

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Relevant plugins

  • Resharper (version: )

Activity

  1. added
    kind/bug
    triage/untriaged
    on Aug 26, 2019
  2. added
    area/code-generation
    and removed
    triage/untriaged
    on Aug 29, 2019
  3. lextm commented on May 30, 2020

    @lextm

    There is no feasible workaround if controls such as MenuFlyoutItem are used with x:Load. Example,

                <MenuFlyoutItem
                    x:Name="SidebarPinItem"
                    x:Uid="BaseLayoutItemContextFlyoutPinToSidebar"
                    x:Load="False"
                    Click="{Binding PinItem_Click}"
                    Tag="PinItem_FlyoutItem"
                    Text="Pin to sidebar">
                    <MenuFlyoutItem.Icon>
                        <SymbolIcon Symbol="Pin" />
                    </MenuFlyoutItem.Icon>
                </MenuFlyoutItem>
    

    If we change that to

                <MenuFlyoutItem
                    x:Key="SidebarPinItem"
                    x:Uid="BaseLayoutItemContextFlyoutPinToSidebar"
                    x:Load="False"
                    Click="{Binding PinItem_Click}"
                    Tag="PinItem_FlyoutItem"
                    Text="Pin to sidebar">
                    <MenuFlyoutItem.Icon>
                        <SymbolIcon Symbol="Pin" />
                    </MenuFlyoutItem.Icon>
                </MenuFlyoutItem>
    

    then Uno XAML code generator works, but UWP will fail with error message,

    Error
    
    Element must have x:Name attribute specified since it uses x:Load.
    Files_Uno.UWP
    E:\files-uwp\Files_Uno\Files_Uno.Shared\UserControls\LayoutModes\GenericFileBrowser.xaml
    254
    

    Therefore, this issue must be fixed

  4. added
    project/styling 👔
    on May 31, 2020
  5. jeromelaban commented on May 31, 2020

    @jeromelaban
    Member

    It may be adjusted by #3183.

    /cc @davidjohnoliver

  6. davidjohnoliver commented on Jun 1, 2020

    @davidjohnoliver
    Contributor

    Yes this works correctly with #1766. I'll add a test for it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/code-generationkind/bugproject/styling 👔

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions