1

在我的应用程序中,我想创建一个GradientStop带有系统颜色的渐变线,我正在尝试这样做:

<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

我应该怎么做才能解决这个问题?

4

2 回答 2

3

GradientStop.Color需要颜色,而不是画笔。使用PhoneChromeColorandPhoneInverseBackgroundColor代替:

<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>
于 2013-01-16T15:43:05.667 回答
0

我不确定,但似乎您可能将静态颜色设置为画笔。很难说,因为您从未将代码发布到“PhoneChromeBrush”或“PhoneInverseBackgroundBrush”的静态资源中。但是您正在使用这些设置渐变停止,如果它们本身就是可能破坏您的代码的渐变。通常你为渐变保留“画笔”,所以我不确定:

你能不能做这样的事情:

<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>
于 2013-01-16T15:06:20.850 回答