How can I use a system color for gradients in Windows Phone 8.1?

0

I'd like to have a sytem color from a theme as part of a LinearGradientBrush in Windows Phone. So instead of

<LinearGradientBrush x:Key="StandardGradientBackground"  EndPoint="0.5,1" StartPoint="0.5,0.5">
    <GradientStop Color="#FF660000" Offset="0"/>
    <GradientStop Color="#FFff0033" Offset="1"/>
</LinearGradientBrush>

I'd like to use something like

<LinearGradientBrush x:Key="StandardGradientBackground"  EndPoint="0.5,1" StartPoint="0.5,0.5">
    <GradientStop Color="SystemColors.ActiveBorderColor" Offset="0"/>
    <GradientStop Color="#FFff0033" Offset="1"/>
</LinearGradientBrush>

I tried different syntaxes and also read this post, but "static is not supported in a Windows App Project" as Visual Studio says.

I also tried to achieve the same programmatically

LinearGradientBrush linearGradientBrush =
    new LinearGradientBrush
    {
        StartPoint = new Point( 0.5, 0.5 ),
        EndPoint = new Point( 0.5, 1 )
    };
Color currentAccentColorHex = (Color)Current.Resources[ "PhoneAccentColor" ];
linearGradientBrush.GradientStops.Add( new GradientStop
{
    Color = currentAccentColorHex,
    Offset = 0
} );
linearGradientBrush.GradientStops.Add( new GradientStop
{
    Color = Colors.Black,
    Offset = 1
} );

As soon as I get to the line where I try to access (Application.)Current.Resources I end up with a System.Exception with Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)).

Any ideas?

Update

I'm trying to set this in the App.xaml (respectively App.xaml.cs for the programmatic approach) file, just in case that would mean to take any special steps into account.

c#
xaml
windows-phone-8.1
asked on Stack Overflow Dec 13, 2015 by Gorgsenegger • edited May 23, 2017 by Community

1 Answer

1
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0.5">
    <GradientStop Color="{StaticResource SystemColorControlAccentColor}" Offset="0"/>
    <GradientStop Color="#FFff0033" Offset="1"/>
</LinearGradientBrush>
answered on Stack Overflow Dec 13, 2015 by Michal Kania

User contributions licensed under CC BY-SA 3.0