Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:03:54+00:00 2026-06-18T01:03:54+00:00

I’m having trouble understanding my problem with drawing groups. I’m creating a map editor

  • 0

I’m having trouble understanding my problem with drawing groups. I’m creating a map editor in wpf which is my first wpf project and I have been searching/playing around with drawing groups.

I have a set of tiles on the left side that on app startup populate based off of a folder of sprites. They all layout according to rules I have set(3 sets of tiles per row at 32 pixels each). Example below:

    private void RefreshTileList()
    {
        // For now load in all textures as possible tiles
        DrawingGroup dGroup = new DrawingGroup();
        Rect r = new Rect();
        r.X = 0.0;
        r.Y = 0.0;
        r.Width = Settings.Default.TileThumbWidth;
        r.Height = Settings.Default.TileThumbHeight;
        foreach (WPFTexture tex in imgFind.TileTextures)
        {
            ImageDrawing iDraw = new ImageDrawing(tex.src, r);

            dGroup.Children.Add(iDraw);

            r.X += r.Width;
            if (r.X > r.Width * Settings.Default.TileThumbMaxColumns)
            {
                r.X = 0.0;
                r.Y += r.Height;
            }
        }

        // Make a drawing image and send it to the Image in canvas
        DrawingImage drawImage = new DrawingImage(dGroup);
        tileImage.Source = drawImage;
    }

Now I Image control in another canvas which I want to do the same exact thing with exception that the tiles are placed dynamically. Here is what I have so far:

    private void AreaDrawingCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if(curSelIndex > -1 && curSelIndex < imgFind.TileTextures.Count)
        {
            BitmapSource tileSrc = imgFind.TileTextures[curSelIndex].src;

            Point mousePos = e.GetPosition(sender as Canvas);
            Size size = new Size(tileSrc.Width, tileSrc.Height);
            Rect r = new Rect(mousePos, size);
            ImageDrawing iDraw = new ImageDrawing(tileSrc, r);

            areaDrawGroup.Children.Add(iDraw);

        }
    }

And here is the initialization of what uses areaDrawGroup:

        // Setup drawing for area
        DrawingImage areaDrawImage = new DrawingImage(areaDrawGroup);
        areaImage.Source = areaDrawImage;
        areaImage.Stretch = Stretch.None;
        AreaDrawingCanvas.Children.Add(areaImage);

If I do not add in a dead image located at point(0, 0) in the draw group and I click on the image control. It will offset to a weird location. As I continue to click more towards the top left location it correct where it draws the tile while shifting all the other ones over.

My question is where could I find a good tiling example or what have I done wrong? Because adding in a dead image to fix where other images locate seems like a really bad hack to something simple I missed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:03:55+00:00Added an answer on June 18, 2026 at 1:03 am

    Here is what I did to solve this for now. I have a i7 and used a list of drawingvisuals. Don’t have a problem with it. I thought at one point I should use one drawing visual and add each image to the same visual. The problem with that is if I add a tile I have to re-open the render and redo all the drawing. Since I don’t have any hiccups I decided not to use my time on that method.

    Here is code to copy and paste:

    1. Make a class that derives framework element and add in the overrides as seen

      public class AreaDrawingEdit : FrameworkElement
      {
      public VisualCollection Visuals { get; set; }
      const double COLLISION_OPACITY = 0.8;

      public AreaDrawingEdit()
      {
          Visuals = new VisualCollection(this);
      }
      
      public void AddRenderTile(DrawingTile tile)
      {
          // Add the tile visual 
          tile.visual = new DrawingVisual();
          InvalidateTile(tile);
          Visuals.Add(tile.visual);
      
          // Add in collision visual
          tile.colVol.visual = new DrawingVisual();
          InvalidateCollisionVol(tile.colVol);
          Visuals.Add(tile.colVol.visual);
      }
      
      public void RemoveRenderTile(DrawingTile tile)
      {
          Visuals.Remove(tile.visual);
          Visuals.Remove(tile.colVol.visual);
      }
      
      public void InvalidateTile(DrawingTile tile)
      {
          // Set up drawing rect for new tile
          Rect r = new Rect(tile.pos, new Size(tile.tileTex.src.PixelWidth, tile.tileTex.src.PixelHeight));
      
          DrawingContext dc = tile.visual.RenderOpen();
          dc.DrawImage(tile.tileTex.src, r);
          dc.Close();
      }
      
      public void InvalidateCollisionVol(CollisionVol vol)
      {
          Rect r = new Rect(vol.pos, vol.size);
      
          DrawingContext dc = vol.visual.RenderOpen();
          dc.PushOpacity(COLLISION_OPACITY);
          dc.DrawImage(vol.src, r);
          dc.Pop();
          dc.Close();
      }
      
      protected override int VisualChildrenCount
      {
          get { return Visuals.Count; }
      }
      
      protected override Visual GetVisualChild(int index)
      {
          if (index < 0 || index >= Visuals.Count)
          {
              throw new ArgumentOutOfRangeException();
          }
      
          return Visuals[index];
      }
      

      }

    2. Add the framework element thing you made into your xaml file somewhere.
      lessthan local:AreaDrawingEdit Canvas.Left=”0″ Canvas.Top=”0″ OpacityMask=”Black” x:Name=”areaDrawingEdit” backslashgreaterthan

    Enjoy the solution to my misery of figuring it out the hard-way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have been unable to fix a problem with Java Unicode and encoding. The
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.