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.
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0.5">
<GradientStop Color="{StaticResource SystemColorControlAccentColor}" Offset="0"/>
<GradientStop Color="#FFff0033" Offset="1"/>
</LinearGradientBrush>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.