簡體   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