繁体   English   中英

如何在App.xaml Xamarin表单中为CustomButton定义样式?

[英]How define style in App.xaml Xamarin Forms for CustomButton?

如何在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}" />

您可以在例如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>

在App.xaml中

给CustomButton整个路径,如TargetType =“ Control:CustomButton”,并在顶部定义Control,例如

 xmlns:Control="clr-namespace:xyz" 

 <Style x:Key="CustomButtonSmall" TargetType="Control:CustomButton">
            <Setter Property="FontSize" Value="14" />
        </Style>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM