views:

15

answers:

1

Can anyone tell me (or send a link) step-by-step instructions of creating a vector image in expression design and importing it into Visual Studio and using it as the content of a control?

+1  A: 
  1. Open Design
  2. Draw Something
  3. File | Export Format = WPF Resource Dictionary This will produce a Drawing Brush of your object

  4. In your WPF application create a rectangle

  5. Set the Retangle Fill Property to the drawing brush created in design

Here is what the WPF code looks like (where that drawing brush is what I exported from Design:

<Window x:Class="StackOverflow.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">

    <Window.Resources>
        <DrawingBrush x:Key="Layer_1" Stretch="Uniform">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <DrawingGroup.Children>
                        <GeometryDrawing Brush="#FFFFFFFF" Geometry="F1 M 0.5,21.0313C 75,88.0313 57.5,-51.4688 1.5,22.5313">
                            <GeometryDrawing.Pen>
                                <Pen LineJoin="Round" Brush="#FF000000"/>
                            </GeometryDrawing.Pen>
                        </GeometryDrawing>
                    </DrawingGroup.Children>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Window.Resources>
    <Grid>
        <Rectangle Fill="{StaticResource Layer_1}" />
    </Grid>
</Window>
Foovanadil
I'm getting "The Resource 'Layer_1' could not be resolved" which is the name of my brush. The definition of my DrawingBrush is in the xaml file created by Expression Design. I have this file's build action to be a resource. Is that correct?
Lee Warner
If you leave the drawing brush in the XAML file that Expression design creates then you need to merge in the resource dictionary. In my example I copied the drawing brush out of the file Expression Design created to simplify things, I suggest you do the same if you are not familiar with merged dictionaries in WPF.
Foovanadil