[英]How to change Font/Color/Size in Xamarin C#
我在C#/ Xamarin中制作混合應用程序,我想為所有應用程序(iOS,Android,Windows Phone)制作自定義菜單。
所以,我創建一個MasterPage
作為我的菜單。
public MasterPage()
{
InitializeComponent();
var masterPageItems = new List<MenuItem>();
masterPageItems.Add(new MenuItem
{
Title = "Administração",
});
masterPageItems.Add(new MenuItem
{
Title = "Meus Dados",
IconSource = "contacts.png",
TargetType = typeof(MeusDados),
});
masterPageItems.Add(new MenuItem
{
Title = "Dados Cadastrais",
IconSource = "contacts.png",
TargetType = typeof(MeusNegocios),
});
var listView = new ListView
{
ItemsSource = masterPageItems,
ItemTemplate = new DataTemplate(() =>
{
var imageCell = new ImageCell();
imageCell.SetBinding(TextCell.TextProperty, "Title");
imageCell.SetBinding(ImageCell.ImageSourceProperty, "IconSource");
return imageCell;
}),
VerticalOptions = LayoutOptions.FillAndExpand,
SeparatorVisibility = SeparatorVisibility.None
};
Padding = new Thickness(0, 20, 0, 0);
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Fill,
Children = {
listView
}
};
}
這是MenuItem
:
public class MenuItem
{
public string Title { get; set; }
public string IconSource { get; set; }
public Type TargetType { get; set; }
public string Parameter { get; set; }
}
所以現在我想在C#中更改內容頁面,字體,字體顏色,字體大小的大小。 我該怎么辦?
Xamarin Forms字體:字體: https : //developer.xamarin.com/guides/xamarin-forms/user-interface/text/fonts/
例:
var about = new Label {
FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
FontAttributes = FontAttributes.Bold,
Text = "Medium Bold Font"
};
我注意到您使用的是ImageCell,它沒有Font屬性,只有TextColor和DetailColor屬性。 此外,沒有屬性可以獲取ImageCell中的基礎標簽,因此如果您想要完全自定義,最好的選擇是創建自己的ViewCell並將圖像和標簽添加到ViewCell。 然后,您可以使用Font屬性設置標簽樣式。
或者,您可以使用預覽中的主題: https : //developer.xamarin.com/guides/xamarin-forms/themes/
StyleClass StyleClass屬性允許根據主題提供的定義更改視圖的外觀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.