如何更改网格内所有文本框的字体大小,Windows应用程序uwp [英] how to change the font size of all text box within a grid, windows app uwp

查看:51
本文介绍了如何更改网格内所有文本框的字体大小,Windows应用程序uwp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用HTML和CSS开发网页,但是我是Windows应用程序开发的新手,我正在尝试开发通用Windows平台(UWP)应用程序.

I know how to develop webpages with HTML and CSS, but I am new to the windows app development and I am trying to develop an universal windows platform (UWP) application.

让我说我有网格,

 <Grid Name="Grid1">
    <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="Normal">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="600" />
                </VisualState.StateTriggers> 
                <VisualState.Setters>
                    <Setter Target="text1.FontSize" Value="12" />
                    <Setter Target="text2.FontSize" Value="12" />
                    <Setter Target="text3.FontSize" Value="10" />                        
                </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
     <Grid.RowDefinitions>
        <RowDefinition></RowDefinition>
     </Grid.RowDefinitions>
    <TextBlock Name="text1" FontSize="22" Text="hello text">    </TextBlock>
    <TextBlock Name="text2" FontSize="22" Text="hello text1">    </TextBlock>
    <TextBlock Name="text3" FontSize="22" Text="hello text2">    </TextBlock>
</Grid>

是否可以使用单个VisualState更改所有文本框的字体大小.类似我们在HTML中使用CSS类的方法这样的设置,因为我必须根据窗口宽度更改许多文本框的字体大小.

Is it is possible to change the font size of all text box with single VisualState.Setters like how we do in with CSS class in HTML ?, because I have to change many text box font size based on window width.

很抱歉,如果问题太愚蠢和荒谬.预先感谢.

Sorry if if the question is too silly and absurd. Thanks in advance.

推荐答案

您可以使用样式为所有控件应用相同的值.考虑下一个示例:

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>

已编辑

您可以在VisualState的Setter中设置命名样式:

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>

这篇关于如何更改网格内所有文本框的字体大小,Windows应用程序uwp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆