Xamrin.Forms 用户界面——控件——Style——设备样式
来源:互联网 发布:淘宝上找货源 编辑:程序博客网 时间:2024/06/07 12:12
设备样式
使用Xamarin.Forms中内置的动态样式
- PDF用于离线使用
- 下载PDF
- 示例代码:
- 动态样式
- 使用样式
- 相关文章:
- 文字样式
- XAML标记扩展
- 相关API:
- 资源字典
- 样式
- 二传手
让我们知道你对此的感受
最后更新:2016年2月
Xamarin.Forms在Device.Styles类中包含六种动态样式,称为设备样式。
该设备样式:
BodyStyle
CaptionStyle
ListItemDetailTextStyle
ListItemTextStyle
SubtitleStyle
TitleStyle
所有六种样式只能应用于Label
实例。例如,一个Label
显示段落的正文可能会将其Style
属性设置为BodyStyle
。
以下代码示例演示如何在XAML页面中使用设备样式:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Styles.DeviceStylesPage" Title="Device" Icon="xaml.png"> <ContentPage.Resources> <ResourceDictionary> <Style x:Key="myBodyStyle" TargetType="Label" BaseResourceKey="BodyStyle"> <Setter Property="TextColor" Value="Accent" /> </Style> </ResourceDictionary> </ContentPage.Resources> <ContentPage.Content> <StackLayout Padding="0,20,0,0"> <Label Text="Title style" Style="{DynamicResource TitleStyle}" /> <Label Text="Subtitle text style" Style="{DynamicResource SubtitleTextStyle}" /> <Label Text="Body style" Style="{DynamicResource BodyStyle}" /> <Label Text="Caption style" Style="{DynamicResource CaptionStyle}" /> <Label Text="List item detail text style" Style="{DynamicResource ListItemDetailTextStyle}" /> <Label Text="List item text style" Style="{DynamicResource ListItemTextStyle}" /> <Label Text="No style" /> <Label Text="My body style" Style="{StaticResource myBodyStyle}" /> </StackLayout> </ContentPage.Content></ContentPage>
设备样式必须使用DynamicResource
标记扩展名。通过更改文本大小的辅助功能设置,可以在iOS中看到样式的动态特性。设备样式的外观在每个平台上是不同的,如下面的屏幕截图所示:
设备的样式也可以通过设置导出BaseResourceKey
属性键名称为设备样式。在上面的代码示例中,myBodyStyle
继承BodyStyle
并设置重音文字颜色。有关动态样式继承的更多信息,请参阅动态样式继承。
以下代码示例演示了C#中的等效页面:
public class DeviceStylesPageCS : ContentPage{ public DeviceStylesPageCS () { var myBodyStyle = new Style (typeof(Label)) { BaseResourceKey = Device.Styles.BodyStyleKey, Setters = { new Setter { Property = Label.TextColorProperty, Value = Color.Accent } } }; Title = "Device"; Icon = "csharp.png"; Padding = new Thickness (0, 20, 0, 0); Content = new StackLayout { Children = { new Label { Text = "Title style", Style = Device.Styles.TitleStyle }, new Label { Text = "Subtitle style", Style = Device.Styles.SubtitleStyle }, new Label { Text = "Body style", Style = Device.Styles.BodyStyle }, new Label { Text = "Caption style", Style = Device.Styles.CaptionStyle }, new Label { Text = "List item detail text style", Style = Device.Styles.ListItemDetailTextStyle }, new Label { Text = "List item text style", Style = Device.Styles.ListItemTextStyle }, new Label { Text = "No style" }, new Label { Text = "My body style", Style = myBodyStyle } } }; }}
Style
每个Label
实例的属性设置为类中的适当属性Devices.Styles
。
无障碍
该设备样式尊重无障碍偏好,从而可访问性偏好在每个平台上改变字体大小会发生变化。因此,为了支持可访问的文本,请确保将设备样式用作应用程序中任何文本样式的基础。
以下屏幕截图演示了每个平台上的设备样式,字体大小最小:
以下屏幕截图演示了每个平台上的设备风格,最大可访问的字体大小:
概要
Xamarin.Forms在类中包含六种动态样式,称为设备样式Devices.Styles
。所有六种样式只能应用于Label
实例。
阅读全文
0 0
- Xamrin.Forms 用户界面——控件——Style——设备样式
- Xamrin.Forms 用户界面——控件——ListView——ListView 交互
- Xamrin.Forms 用户界面——控件——Text——Fonts
- Xamarin.Forms 用户界面——控件——Style——显示样式
- Xamarin.Forms 用户界面——控件——Style——全局样式
- Xamarin.Forms 用户界面——控件——Style——动态样式
- Xamrin.Froms 用户界面——控件——主题
- Xamrin.Forms 基础——Custom Renderers
- Xamrin.Forms 基础——Behaviors——介绍
- Xamrin.Forms 基础——Behaviors——Attached Behaviors
- Xamarin.Forms 用户界面——控件——Style——介绍
- Xamarin.Forms 用户界面——控件——Style——隐式样式
- Xamarin.Forms 用户界面——控件
- Xamarin.Foms 用户界面——控件——Style——样式继承
- Xamarin.Forms 用户界面——控件——页面
- Xamarin.Forms 用户界面——控件——布局
- Xamarin.Forms 用户界面——控件——View
- Xamarin.Forms 用户界面——控件——Cells
- hdu 5506 bitset 优化
- ThinkInJava(Java编程思想总结)2017.8.9-------操作符
- I Hate It---线段树
- C++中参数传递的两种方式:传值与传址及它们的区别
- nginx.conf配置详解
- Xamrin.Forms 用户界面——控件——Style——设备样式
- LeetCode547. Friends Circles 利用union find | bfs | dfs三种方法解决
- 开启科研之路,写此文以作纪念!
- Linux 问题解决拾遗
- JAVA HttpClient(普通参数、JSON格式参数)
- Mysql读写分离实现的三种方式
- 【牛腩】LinkButton
- SQL FULL JOIN 关键字
- C语言(18)A+B Problem II