xamlxamarin.formsridervisualstatemanagerapp.xaml

Rider Xamarin xaml: "Field Normal is already declared" from VisualStateManager


I'm using Xamarin Forms 4.5.0.617 and want to use a VisualStateManager (https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/visual-state-manager) to change the style if an element is disabled. To apply this to all my styles, I have to use the x:Name="Normal" or "Disabled" or "Focused" multiple times, but Rider (https://www.jetbrains.com/de-de/rider/) says error The app runs correctly (style is changing) but the warning of rider is still annoying.

Am I doing something wrong?

<?xml version="1.0" encoding="utf-8"?>

<Application
    x:Class="ProjectApp.App"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:components="clr-namespace:Project.Components"
    xmlns:converters="clr-namespace:Project.Converters"
    xmlns:helpers="clr-namespace:Project.Helpers"
    xmlns:iconize="clr-namespace:Plugin.Iconize;assembly=Plugin.Iconize">

    <Application.Resources>
        <ResourceDictionary>

            <!--  Text  -->
            <Style
                x:Key="Label"
                TargetType="Label">
                <Setter
                    Property="VisualStateManager.VisualStateGroups">
                    <VisualStateGroupList>
                        <VisualStateGroup>
                            <VisualState
                                x:Name="Normal">
                                <VisualState.Setters>
                                    <Setter
                                        Property="TextColor"
                                        Value="Black" />
                                </VisualState.Setters>
                            </VisualState>
                            <VisualState
                                x:Name="Disabled">
                                <VisualState.Setters>
                                    <Setter
                                        Property="TextColor"
                                        Value="Gray" />
                                </VisualState.Setters>
                            </VisualState>
                            <VisualState
                                x:Name="Focused">
                                <VisualState.Setters>
                                    <Setter
                                        Property="TextColor"
                                        Value="{StaticResource Primary}" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </Setter>
            </Style>

            <!--  Picker  -->
            <Style
                x:Key="Picker"
                TargetType="Picker">
                <Setter
                    Property="FontSize"
                    Value="14" />
                <Setter
                    Property="TextColor"
                    Value="Black" />
                <Setter
                    Property="VerticalOptions"
                    Value="Center" />
                <Setter
                    Property="VisualStateManager.VisualStateGroups">
                    <VisualStateGroupList>
                        <VisualStateGroup>
                            <VisualState
                                x:Name="Normal">
                                <VisualState.Setters>
                                    <Setter
                                        Property="TextColor"
                                        Value="Black" />
                                </VisualState.Setters>
                            </VisualState>
                            <VisualState
                                x:Name="Disabled">
                                <VisualState.Setters>
                                    <Setter
                                        Property="TextColor"
                                        Value="Gray" />
                                </VisualState.Setters>
                            </VisualState>
                            <VisualState
                                x:Name="Focused">
                                <VisualState.Setters>
                                    <Setter
                                        Property="TextColor"
                                        Value="{StaticResource Primary}" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateGroupList>
                </Setter>
            </Style>

        </ResourceDictionary>
    </Application.Resources>
</Application>

Solution

  • You are not doing anything wrong. This is a confirmed known issue with Rider/ReSharper. I have already reported it here.

    What I can suggest is that you upvote the issue and/or write a comment, so that they can escalate it and fix it quickly.