我想同时为控件分配静态和动态样式。 像这样
<Button
Style="{StaticResource homeScreenBackButton}"
Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}">
<Button.Content>
<Image Source="wwwroot/images/homescreen-back2.png" />
</Button.Content>
</Button>
我可以轻松实现
<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>
但是我不想用这种方式对样式进行硬编码。
答案 0 :(得分:0)
显然,您不能同时将Style
之类的单个属性设置为两个不同的值。您可以将Style
设置为另一个:
<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>
用法:
<Button Style="{StaticResource homeScreenBackButton}" />