-2

I want to assign both static and dynamic styles to a control at same time. Something like this

<Button
  Style="{StaticResource homeScreenBackButton}"
  Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}">
    <Button.Content>
      <Image Source="wwwroot/images/homescreen-back2.png" />
    </Button.Content>
</Button>

I could easily achieve this

<Button
  Width="38"
  Height="38"
  HorizontalAlignment="Center"
  Cursor="Hand"
  Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}">
    <Button.Content>
      <Image Source="wwwroot/images/homescreen-back2.png" />
    </Button.Content>
</Button>

But I don't want to hardcode the styles in this way.

mcalex
  • 6,418
  • 5
  • 45
  • 75
Anuj Tamrakar
  • 71
  • 1
  • 8

1 Answers1

0

Obviously you cannot set a single property like Style to two different values simultaneously. You can base a Style on another one though:

<Image x:Key="img" x:Shared="false" Source="wwwroot/images/homescreen-back2.png" />
<Style x:Key="homeScreenBackButton" TargetType="Button" BasedOn="{StaticResource MahApps.Metro.Styles.MetroCircleButtonStyle}">
    <Setter Property="Content" Value="{StaticResource img}" />
</Style>

Usage:

<Button Style="{StaticResource homeScreenBackButton}" />
mm8
  • 150,971
  • 10
  • 50
  • 74