我是 xamarin 和 c# 的新手,我需要一些幫助。
xaml 中的這段代碼,我想讓設計靜態化,并在功能上更改文本和命令以在另一個頁面中使用此組件的設計,并且只更改文本和命令或系結
<Button BackgroundColor="#2196f3"
WidthRequest="300"
CornerRadius="20"
FontSize="Medium"
TextColor="White"
Text="Login"
Command="{Binding LoginCommand}" ></Button>
我該怎么做:)?
uj5u.com熱心網友回復:
您可以使用資源字典,因此您將相同的樣式應用于您的按鈕,只更改文本和命令
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="MyStyleButton" TargetType="Button">
<Setter Property="BackgroundColor" Value="#2196f3" />
<Setter Property="WidthRequest" Value="300" />
<Setter Property="CornerRadius" Value="20" />
<Setter Property="FontSize" Value="Medium" />
<Setter Property="TextColor" Value="White" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout>
<Button
Command="{Binding Command1}"
Style="{StaticResource MyStyleButton}"
Text="Button1" />
<Button
Command="{Binding Command2}"
Style="{StaticResource MyStyleButton}"
Text="Button2" />
<Button
Command="{Binding Command3}"
Style="{StaticResource MyStyleButton}"
Text="Button3" />
</StackLayout>
</ContentPage.Content>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/456302.html
標籤:C# 。网 xamarin.forms
