我知道如何使用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>
关于c# - 如何更改网格内所有文本框的字体大小,Windows应用程序uwp,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39409365/