簡體   English   中英

如何更改網格內所有文本框的字體大小,Windows應用程序uwp

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

我知道如何使用HTML和CSS開發網頁,但是我是Windows應用程序開發的新手,我正在嘗試開發通用Windows平台(UWP)應用程序。

假設我有網格,

 <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類的方法一樣,因為我必須根據窗口寬度更改許多文本框的字體大小。

很抱歉,如果這個問題太愚蠢和荒謬。 提前致謝。

您可以使用樣式為所有控件應用相同的值。 考慮下一個示例:

<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中設置命名樣式:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM