Part III of Building the Diagram Maker Silverlight App

by Bobbi Perreault 1. May 2008 04:35
Share on Facebook

Part III of Building the Diagram Maker Silverlight App

Part I is here: http://www.faxt.com/blog/post/Silverlight-Tools-for-eCommerce-Sites--Infloor-Heating-Diagram-Maker.aspx

 

Part II is here:  http://www.faxt.com/blog/post/Infloor-heating-Diagram-Maker-Part-II.aspx

 

Use Blend to Create the Manifold control for the Diagram Maker

This article is an overview of one way to use Expression Blend to create a control.  This particular control is used in a drawing tool, which is described in part one so I won't repeat myself.  Here, I'm at the good part, which is customizing for my application.  I need a specialized control, one which wouldn't make sense outside of the heating an plumbing industry, that is a Manifold for the Infloor Heating diagram.   So, here's how I create my manifold control.  And the Diagram Maker Silverlight application can be viewed here.

  1. Find a picture of a manifold in my catalog.
  2. Add it to my project so I can use it in Blend.
  3. In Visual Studio, create a new Silverlight Usercontrol.  Call it ManifoldControl.  Copy the contents of the Pen.xaml class into these new files (.xaml and .xaml.cs)  
  4. Change all the PEN references to Manifold (within the xaml and the csharp code)
  5. Go to Workspace.cs and add the Manifold Drawing Tool Type.
public enum DrawingToolMode  {
        None,
        Brush,
        Select,
        Pen,
        Rectangle,
        Manifold,
        PexRun,
    }

 

  1. That gives me my new drawing tool and plugs it into the framework (one more item I'll take care of later is adding the method that will take care of placing the manifold control.
  2. Move into Blend, and bring up the new .xaml file.  It has a Pen in it for an image.  This is what I'll change now.
  3. Add the manifold picture to my project so it's available to add to this .xaml in Blend.  Add it to Manifold.xaml's canvas.
  4. Trace the picture using the pen tool.  I divide this into several sections so I can sort of make it look like the picture when I'm done.
  5. first in expression blend
  6. There are two groups on the left in Blend, ManifoldOver and ManifoldNormal.  I remove all the paths from ManifoldOver and drag the Paths just created when I was tracing my Manifold into ManifoldOver so that they become a part of it's definition.
  7. I color each section by applying and adjust a gradient with the colors picked from the photograph.
  8. I pull the photograph out to where I can see it enough to add the details of the photo on top.
  9. Here's the selected tool state

  1. And here's the unselected tool state:

  1. When that's all done, I can add it to my palette for selection as a drawing tool.
  2. Back in Visual Studio again, add a Manifold Tool Section to the DrawingSurface.cs (scribbler again) class.
private void HandleToolModeChanged (object sender, EventArgs e) {
    if (this.currentTool != null) {
        this.currentTool.Dispose ();
        this.currentTool = null;
    }

    switch (this.Workspace.ToolMode) {
        case DrawingToolMode.Brush:
            this.currentTool = new DrawingPencilTool (this.Drawing, this);
            break;
        case DrawingToolMode.Select:
            this.currentTool = new SelectionTool(this.Drawing, this);
            break;
        case DrawingToolMode.Pen:
            this.currentTool = new PenTool(this.Drawing, this);
            break;
        case DrawingToolMode.Rectangle:
            this.currentTool = new RectangleTool(this.Drawing, this);
            break;
        case DrawingToolMode.Manifold:
            this.currentTool = new ManifoldTool(this.Drawing, this);
            break;
        case DrawingToolMode.PexRun:
            this.currentTool = new PexRun(this.Drawing, this);
            break;
    }
}

 

  1. In the  Page.Xaml.cs, add the Manifold Tool selection Option.

 

private void HandleToolModeChanged (object sender, EventArgs e)
       {
           Brush.setToggleMode(this.Workspace.ToolMode == DrawingToolMode.Brush);
           Select.setToggleMode(this.Workspace.ToolMode == DrawingToolMode.Select);
           Pen.setToggleMode(this.Workspace.ToolMode == DrawingToolMode.Pen);
           RectangleTool.setToggleMode(this.Workspace.ToolMode == DrawingToolMode.Rectangle);
           ManifoldTool.setToggleMode(this.Workspace.ToolMode == DrawingToolMode.Manifold);
           Workspace.SelectionSet.Clear();

       }

 

Comments are closed

 

RSS Feed FriendFeed