Xamarin 当我使用XAML时,它会继承像颜色这样的属性吗?

Xamarin 当我使用XAML时,它会继承像颜色这样的属性吗?,xamarin,xamarin.forms,Xamarin,Xamarin.forms,如果我有此代码: <Grid Margin="10"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />

如果我有此代码:

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

然后里面的所有东西都会变成灰色?

不,这是不可能的。您必须在继承的控件上创建隐式样式或将颜色设置为默认的灰色。

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

可以创建如下命名样式:

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

并将其应用于如下标签:

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

No,每个XAML元素在运行时都成为一个具体的实例对象,没有对象继承,有网格、StackLayout等容器。。如果为其指定背景色,则ViewElement中未覆盖网格的任何部分都可能显示该颜色(取决于平台相关视图自身的绘制方式),或者如果明确将该ViewElement设置为具有清晰/透明的背景,则容器的颜色将显示。