如何在App.xaml中为CustomButton定义样式?
的App.xaml
<Style x:Key="CustomButtonSmall" TargetType="CustomButton">
<Setter Property="FontSize" Value="14" />
</Style>
MyPage.xaml
<local:CustomButton Text="{i18n:Translate CreateAccountButton}"
Grid.Column="0" Command="{Binding CreateAccountCommand}"
Type="Normal" Style="{StaticResource CustomButtonSmall}" />
答案 0 :(得分:1)
您可以在Window.xaml中定义样式:
<Window>
<Window.Resources>
<Style x:Key="myStyle" TargetType="Button">
<Setter Property="Background" Value="Orange" />
<Setter Property="FontStyle" Value="Italic" />
</Style>
</Window.Resources>
然后你用你的目标按钮:
<Button Style="{StaticResource myStyle}">Buttontext</Button>
答案 1 :(得分:0)
在App.xaml中
赋予CustomButton整个路径,如TargetType =&#34; Control:CustomButton&#34; 并在顶部定义控件,如
xmlns:Control="clr-namespace:xyz"
<Style x:Key="CustomButtonSmall" TargetType="Control:CustomButton">
<Setter Property="FontSize" Value="14" />
</Style>