2

I am overlaying several XAML-defined drawing groups in a resource dictionary, and noticed some strange behavior. If I define a DrawingImage thus:

<DrawingImage x:Key="My_Icon">
    <DrawingImage.Drawing>
        <DrawingGroup>
            <DrawingGroup.Children>
                <StaticResource ResourceKey="Background" />
                <StaticResource ResourceKey="Foreground" />
                <DrawingGroup>
                    <!-- some content here for an overlay -->
                </DrawingGroup>
            </DrawingGroup.Children>
        </DrawingGroup>
    </DrawingImage.Drawing>
</DrawingImage>

things work fine at design time, but at runtime I get an exception:

'XAML Node Stream: Value of 'System.Windows.Markup.StaticResourceHolder' must follow a StartObject and StartMember.' Line number '14' and line position '22'.

However, if I insert an empty DrawingGroup tag before my static resources, everything works fine:

<DrawingImage x:Key="My_Icon">
    <DrawingImage.Drawing>
        <DrawingGroup>
            <DrawingGroup.Children>
                <DrawingGroup />
                <StaticResource ResourceKey="Background" />
                <StaticResource ResourceKey="Foreground" />
                <DrawingGroup>
                    <!-- some content here for an overlay -->
                </DrawingGroup>
            </DrawingGroup.Children>
        </DrawingGroup>
    </DrawingImage.Drawing>
</DrawingImage>

Does anyone know why this occurs? I am assuming it is a general XAML node processing bug and not specific to DrawingGroups, but I could be wrong...

Note that the StaticResources in question are DrawingGroups:

<DrawingGroup x:Key="Background">
    <DrawingGroup.Children>
        <GeometryDrawing Geometry="M 3,1.00001L 29,1.00001C 30.1046,1.00001 31,1.89544 31,3.00001L 31,29C 31,30.1046 30.1046,31 29,31L 3,31C 1.89543,31 1,30.1046 1,29L 1,3.00001C 1,1.89544 1.89543,1.00001 3,1.00001 Z ">
            <GeometryDrawing.Pen>
                <Pen LineJoin="Round" Brush="#FFEB8E00"/>
            </GeometryDrawing.Pen>
            <GeometryDrawing.Brush>
                <RadialGradientBrush RadiusX="0.516666" RadiusY="0.516666" Center="0.499999,0.966667" GradientOrigin="0.499999,0.966667">
                    <RadialGradientBrush.GradientStops>
                        <GradientStop Color="#FFFFECA8" Offset="0"/>
                        <GradientStop Color="#FFFFCD52" Offset="0.2"/>
                        <GradientStop Color="#FFFFCD52" Offset="0.669767"/>
                        <GradientStop Color="#FFFFB100" Offset="0.95814"/>
                    </RadialGradientBrush.GradientStops>
                    <RadialGradientBrush.RelativeTransform>
                        <TransformGroup/>
                    </RadialGradientBrush.RelativeTransform>
                </RadialGradientBrush>
            </GeometryDrawing.Brush>
        </GeometryDrawing>
        <GeometryDrawing Brush="#67F9F0AD" Geometry="M 4,19L 28,19C 29.1046,19 30,19.8954 30,21L 30,28C 30,29.1046 29.1046,30 28,30L 4,30C 2.89543,30 2,29.1046 2,28L 2,21C 2,19.8954 2.89543,19 4,19 Z "/>
    </DrawingGroup.Children>
</DrawingGroup>

My usage is simple- I am binding this whole DrawingImage to an Infragistics WPF button control:

<igWPF:ButtonTool igWPF:RibbonGroup.MaximumSize="ImageAndTextLarge" Caption="New Item" SmallImage="{StaticResource My_Icon}" LargeImage="{StaticResource My_Icon}" />
Chris Shain
  • 50,833
  • 6
  • 93
  • 125
  • Chris what does your code behind look like ? check this site look like http://stackoverflow.com/questions/1513892/how-to-bind-gradientstop-colours-or-gradientstops-property-in-silverlight – MethodMan Dec 27 '12 at 21:43
  • @DJKRAZE there is no binding going on here at all. I'll update with my usage. I'm only doing this to be able to re-use the icon background and overlays. – Chris Shain Dec 27 '12 at 21:46
  • @DJKRAZE correction- I am using this whole image via a binding, but I can't imagine that affects anything. – Chris Shain Dec 27 '12 at 21:48

0 Answers0