当我使用XAML时,它是否继承了像color这样的属性?(When I am using XAML does it inherit properties like color?)

编程入门 行业动态 更新时间:2024-10-20 11:33:36
当我使用XAML时,它是否继承了像color这样的属性?(When I am using XAML does it inherit properties like color?)

如果我有这个代码:

<Grid Margin="10"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <local:HOV Grid.Row="0" /> <local:HST Grid.Row="1" /> <local:HAC Grid.Row="2" /> <local:HAI Grid.Row="3" /> </Grid>

我想在网格内的所有内容中设置文本的颜色我可以指定:

TextColor="Gray"

在然后里面的一切都会有灰色?

If I have this code:

<Grid Margin="10"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <local:HOV Grid.Row="0" /> <local:HST Grid.Row="1" /> <local:HAC Grid.Row="2" /> <local:HAI Grid.Row="3" /> </Grid>

and I want to set the color of the text in everything inside the grid can I just specify:

TextColor="Gray"

in the and then everything inside there will be Gray color?

最满意答案

Grid不支持TextColor属性。 您可以使用隐式样式并为内容页面上的所有标签着色,如下所示:

<ContentPage.Resources> <Style TargetType="Label"> <Setter Property="TextColor" Value="Gray"></Setter> </Style> </ContentPage.Resources>

您可以创建这样的命名样式:

<ContentPage.Resources> <Style x:Key="lblStyle" TargetType="Label"> <Setter Property="TextColor" Value="Red"></Setter> </Style> </ContentPage.Resources>

并将其应用于这样的标签:

<Label Style="{StaticResource lblStyle}" Text="Test" Grid.Row="0" />

Grid doesn't support the TextColor property. You can use an implicit style and color all the labels on a content page like this:

<ContentPage.Resources> <Style TargetType="Label"> <Setter Property="TextColor" Value="Gray"></Setter> </Style> </ContentPage.Resources>

You can create a named style like this:

<ContentPage.Resources> <Style x:Key="lblStyle" TargetType="Label"> <Setter Property="TextColor" Value="Red"></Setter> </Style> </ContentPage.Resources>

And apply it to a label like this:

<Label Style="{StaticResource lblStyle}" Text="Test" Grid.Row="0" />

更多推荐

本文发布于:2023-07-17 07:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141113.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:当我   属性   继承了   XAML   color

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!