how to change the font size of all text box within a grid, windows app uwp

允我心安 提交于 2019-12-06 07:34:15

You can use styles to apply same values for all controls. Consider next example:

<Grid>
    <Grid.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="FontSize" Value="22"/>
        </Style>
    </Grid.Resources>

    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0" Text="hello text" />
    <TextBlock Grid.Row="1" Text="hello text1" />
    <TextBlock Grid.Row="2" Text="hello text2" />
</Grid>

Edited

You can set a named style in a Setter of VisualState:

<Grid Name="Grid1">
    <Grid.Resources>
        <Style x:Key="TextBlockStyle" TargetType="TextBlock">
            <Setter Property="FontSize" Value="22"/>
        </Style>
    </Grid.Resources>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup>
            <VisualState x:Name="Normal">
                ...
                <VisualState.Setters>
                    <Setter Target="text1.Style" Value="{StaticResource TextBlockStyle}" />
                    ...
                </VisualState.Setters>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    ...
</Grid>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!