在我的应用程序中,我想创建一个褪色线,有GradientStop
s与系统颜色,我试图这样做:
<UserControl.Resources>
<Style x:Key="Divider" TargetType="Rectangle">
<Setter Property="Height" Value="2" />
<Setter Property="Fill">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="{StaticResource PhoneChromeBrush}" Offset="0.0" />
<GradientStop Color="{StaticResource PhoneInverseBackgroundBrush}" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
但是当我尝试编译项目时,我得到以下错误:
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll
An exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll but was not handled in user code
我该怎么做来解决这个问题?
GradientStop.Color
需要颜色,而不是画笔。使用PhoneChromeColor
和PhoneInverseBackgroundColor
代替:
<UserControl.Resources>
<Style x:Key="Divider" TargetType="Rectangle">
<Setter Property="Height" Value="2" />
<Setter Property="Fill">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="{StaticResource PhoneChromeColor}" Offset="0.0" />
<GradientStop Color="{StaticResource PhoneInverseBackgroundColor}" Offset="1.0" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
我不确定,但似乎你可能正在设置一个静态颜色作为画笔。这是很难告诉,因为你从来没有发布代码到你的静态资源为'PhoneChromeBrush'或'PhoneInverseBackgroundBrush'。但是你用这些设置渐变停止,如果它们本身就是渐变,可能会破坏你的代码。通常你会为渐变保留"brush",所以我不确定:
你能不能不要这样做:
<UserControl.Resources>
<LinearGradientBrush x:Key="MoneyBrush" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#3A883A" Offset="1" />
<GradientStop Color="#FFFFFF" Offset="0" />
<GradientStop Color="#FF53AA75" Offset="0.50" />
<GradientStop Color="#073307" Offset="0.95" />
</LinearGradientBrush>
<Style x:Key="Divider" TargetType="Rectangle">
<Setter Property="Height" Value="2" />
<Setter Property="Fill" Value="{StaticResource MoneyBrush}"/>
</Style>
</UserControl.Resources>