【发布时间】:2015-12-13 13:05:50
【问题描述】:
我想要一个主题的系统颜色作为 Windows Phone 中LinearGradientBrush 的一部分。所以不是
<LinearGradientBrush x:Key="StandardGradientBackground" EndPoint="0.5,1" StartPoint="0.5,0.5">
<GradientStop Color="#FF660000" Offset="0"/>
<GradientStop Color="#FFff0033" Offset="1"/>
</LinearGradientBrush>
我想使用类似的东西
<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>
我尝试了不同的语法,还阅读了this post,但正如 Visual Studio 所说,"static is not supported in a Windows App Project"。
我也尝试以编程方式实现同样的目标
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
} );
一旦我到达尝试访问 (Application.)Current.Resources 的行,我就会得到一个 System.Exception 和 Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))。
有什么想法吗?
更新
我正在尝试在App.xaml(对于编程方法分别为App.xaml.cs)文件中进行设置,以防万一这意味着需要考虑任何特殊步骤。
【问题讨论】:
-
你试过this way吗? :
((SolidColorBrush)App.Current.Resources["PhoneAccentBrush"]).Color -
@har 感谢您的建议,不幸的是我最终得到了相同的结果。在访问
Current.Resources正常之前,演员不会发生,所以原因可能在其他地方。
标签: c# xaml windows-phone-8.1