Get Variations of Accent color in UWP

2019-05-01 05:53发布

问题:

I'm trying to get a lighter variation of accent color using theme resource SystemAccentColorLight1 SystemAccentColorLight2 ...

I'm getting this exception: The text associated with this error code could not be found.

Cannot find a Resource with the Name/Key SystemAccentColorLight1 [Line: 15 Position: 19]

<Grid Background="{ThemeResource ResourceKey= SystemAccentColorLight1}"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="60" />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Image Source="{Binding Path=Owner.ProfileImage}" Width="50" Height="50" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2"></Image>
            <TextBlock Text="{Binding Title}" FontSize="12" TextWrapping="WrapWholeWords" FontWeight="SemiBold" Grid.Column="1" Grid.ColumnSpan="2"/>
            <TextBlock Text="{Binding Path=Owner.DisplayName}" VerticalAlignment="Bottom" HorizontalAlignment="Left" FontSize="9" Grid.Column="1" Grid.Row="1" />
        </Grid>

https://msdn.microsoft.com/windows/uwp/style/color?f=255&MSPPError=-2147217396

In XAML, the primary accent color is exposed as a theme resource named SystemAccentColor. The shades are available as SystemAccentColorLight3, SystemAccentColorLight2, SystemAccentColorLight1, SystemAccentColorDark1, SystemAccentColorDark2, and SystemAccentColorDark3. Also available programmatically via UISettings.GetColorValue and the UIColorType enum.

回答1:

As @Mark W said, the SystemAccentColorLight1 is from a newer SDK.

I test it with Window 10 Enterprise Insider Preview Edition and OS Build is 14316.1000. It can get the lighter variation of accent color.

You're welcome to join the Windows Insider Program and you can download preview SDK to use this feature.

Remarks:

Some information relates to pre-released product which may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.