增加整个Silverlight应用的字体大小的最好方法是什么?
发布于 2010-09-13 23:43:47
Control class为您提供了一个FontSize属性,因此,如果您设置了一个基本样式,您的其他样式可以继承此属性。或者,您可以像下面的代码所示将其设置为通用的。UserControl和ContentControl都继承自Control,因此您可以在App.xaml中添加一个定义:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Prototype.App"
>
<Application.Resources>
<Style TargetType="Control" x:Key="DefaultStyle">
<Setter Property="FontSize" Value="24"/>
</Style>
</Application.Resources>
</Application>然后是你的页面:
<UserControl x:Class="HermesPrototype.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Style="{StaticResource DefaultStyle}"
>
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<TextBlock Text="Hello world" />
<TextBox Text="Edit me"/>
</StackPanel>
</Grid>
</UserControl>请注意用户控件中的Style属性。不过,这可能会有缺点,我不确定。
发布于 2010-09-13 23:07:01
如果您想要在整个应用程序中应用全局字体大小增加,我所知道的唯一方法是使用缩放渲染器转换放大最上面的XAML窗口,但您还必须缩小实际大小以补偿,这样整个应用程序大小就不会改变。
例如,如果您将shell放大10%以获得10%的大字体,则必须将缩放的高度和宽度减小10%,以使其仍然适合相同的区域,只是放大的内容。
这一切都假设您已经在Star大小的网格行/列中构建了视图和子视图,以便行和列保持相同的相对大小。
(或者,您也可以动态运行visualroot并动态更改字体大小,但这不是一个很好的方法)。
如果你有更多关于你正在尝试解决的实际问题的信息,这将会有所帮助。
希望这能有所帮助。
https://stackoverflow.com/questions/3701547
复制相似问题