WPF XAML:如何;将动态变量分配给gradientstop值

时间:2015-04-10 15:06:41

标签: wpf xaml

我有一个在XAML中声明的绘图画笔,并且画笔工作正常,是否可以为GradientStop的颜色值指定动态变量?

喜欢" {DynamicResource execl_1}"

    <DrawingBrush x:Key="Column_B_GRAD">
        <DrawingBrush.Drawing>
            <DrawingGroup>
                <GeometryDrawing>
                    <GeometryDrawing.Brush>
                        <RadialGradientBrush Center="0.5,0.4" RadiusX="0.6" RadiusY="1" GradientOrigin="0.4,0.4">
                            <GradientStop Color="#ffffe1" Offset="0"/>
                            <GradientStop Color="#f8e737" Offset="0.461"/>
                            <GradientStop Color="#e79b00" Offset="1"/>
                        </RadialGradientBrush>
                    </GeometryDrawing.Brush>
                    <GeometryDrawing.Geometry>
                        <RectangleGeometry Rect="0,0 1,1" />
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
                <GeometryDrawing>
                    <GeometryDrawing.Brush>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1" SpreadMethod="Pad">
                            <GradientStop Color="#FFFFFFFF" Offset="0"/>
                            <GradientStop Color="#39FFFFFF" Offset="1"/>
                        </LinearGradientBrush>
                    </GeometryDrawing.Brush>
                    <GeometryDrawing.Geometry>
                        <RectangleGeometry Rect="0,0 1,0.5" />
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingGroup>
        </DrawingBrush.Drawing>
    </DrawingBrush>

1 个答案:

答案 0 :(得分:0)

如下所示使用SolidColorBrush并定义键

SolidColorBrush x:Key =&#34; ReadOnlyTextBrush&#34;颜色=&#34;#FFFFC154&#34;

TextBox Foreground =&#34; {DynamicResource ReadOnlyTextColor}&#34;