What is the best way to inc开发者_开发百科rease the fontsize for an entire Silverlight app?
The Control class gives you a FontSize property, so if you set a base style your other styles could inherit from this. Or you can just set it universally as the code below shows. UserControl
and ContentControl
both inherit from Control
, so you could put a definition in you 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>
And then your page:
<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>
Notice the Style
property in the user control. There may be drawbacks to this though, I'm not sure.
If you want to apply a global font size increase across the entire application, the only way I know of is to scale up your topmost XAML window using a scaling rendertransform, but you must also resize the actual dimensions down to compensate, so that the overall app size does not change.
e.g. if you scale the shell up by 10% to get 10% larger fonts, you must decrease the Height and Width of the scale by 10% so that is still fits the same area, just with scaled up content.
This all assumes you have built the views and sub-views within Star-sized grid rows/columns so that rows and columns remain the same relative sizes.
(Alternatively you could dynamically run though the visualroot and change font sizes on the fly, but that is not a great way to approach it).
If you have more info about the actual problem you are trying to solve it would help.
Hope this helps.
精彩评论