Home > Software engineering >  button BackgroundColor does not change as expected
button BackgroundColor does not change as expected

Time:11-06

Button BackgroundColor cannot change using ResourceDictionary style

in App.xaml

    <Application.Resources>
        <ResourceDictionary>
            <Color x:Key="WarningButtonBackGroundColor">#eb8916</Color>
            
            <Style x:Key="WarningButtonStyle" TargetType="Button">
                <Setter Property="BackgroundColor" Value="{StaticResource WarningButtonBackGroundColor}"></Setter>
            </Style>

        </ResourceDictionary>
    </Application.Resources>

in page.xaml

<Button Text="Delete" Style="{StaticResource WarningButtonStyle}"></Button>

button BackgroundColor did not as expected

CodePudding user response:

Still the same output.

App.xaml

  <Application.Resources>
    <ResourceDictionary>
        <Color x:Key="WarningButtonBackGroundColor">#eb8916</Color>
        <Style x:Key="WarningButtonStyle" TargetType="Button">
            <Setter Property="BackgroundColor" Value="{StaticResource WarningButtonBackGroundColor}" />
        </Style>

    </ResourceDictionary>
</Application.Resources>

MainPage.xaml

 <Button Style="{StaticResource WarningButtonStyle}" Text="Delete" />

enter image description here

  • Related