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

  • Home
  • SEARCH
  • 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 3425434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:35:36+00:00 2026-05-18T06:35:36+00:00

I have a WPF canvas that I can scale, scroll and whatever. Now I

  • 0

I have a WPF canvas that I can scale, scroll and whatever.
Now I want to draw (tiling) gridlines on it – preferably depending on the scale, which means that when you zoom out the old gridlines fade away and new (bigger scale, but due to zooming seemingly the same) gridlines fade in.

I’ve heard some people yelling “Tilebrush!”, but I can’t google any example of it.

Can anybody point me in the right direction – not just to the MSDN page of the tilebrush, but on how to efficiently draw gridlines on my zoomable canvas ? 🙂

  • 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-05-18T06:35:37+00:00Added an answer on May 18, 2026 at 6:35 am

    The easiest solution is to use a VisualBrush to draw your gridlines:

    <Canvas>
      <Canvas.Background>
        <VisualBrush TileMode="Tile" Stretch="Fill" Viewport="0 0 50 50" ViewportUnits="Absolute" ViewboxUnits="Absolute" >
          <VisualBrush.Visual>
            <Grid>
              <Rectangle Width="1" Height="0.03" Fill="Gray" HorizontalAlignment="Left" VerticalAlignment="Top" />
              <Rectangle Height="1" Width="0.03" Fill="Gray" HorizontalAlignment="Left" VerticalAlignment="Top" />
            </Grid>
          </VisualBrush.Visual>
        </VisualBrush>
      </Canvas.Background>
    </Canvas>
    

    You can change the gridlines by adjusting the Viewport coordinates and the gridline width by adjusting the rectangle Height and Width (currrently 0.03).

    A more efficient solution is available using a DrawingBrush, but working with drawings is not as simple. This draws gridlines using a DrawingBrush:

    <Canvas>
      <Canvas.Background>
        <DrawingBrush TileMode="Tile" Stretch="Fill" Viewport="0 0 50 50" ViewportUnits="Absolute" ViewboxUnits="Absolute" >
          <DrawingBrush.Drawing>
            <GeometryDrawing Geometry="M0,0 L0,1 0.03,1 0.03,0.03 1,0.03 1,0 Z" Brush="Gray" />
          </DrawingBrush.Drawing>
        </DrawingBrush>
      </Canvas.Background>
    </Canvas>
    

    To change the gridlines as you zoom out, just recompute them whenever the zoom changes. You can determine just how zoomed-in a given visual is with this code:

    var zoom = visual
                 .TransformToAncestor(Window.FromVisual(visual))
                 .Transform(new Point(1,1));
    
    if(zoom.X>10 || zoom.Y>10)
      // Use finer gridlines
    else
      // Use coarser gridlines
    

    If you really want to “fade in” the gridlines, you can use two Canvasas under your main Canvas, and set the opacity on the finer gridlines as a function of the exact zoom in use.

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

Sidebar

Related Questions

I'm trying to have a WPF canvas with rounded rectangles on that I can
I have a WPF Window with a Canvas that is used to show a
I'm learning WPF at the moment. I have a vector graphics canvas that I'd
I have a point on a canvas that I want to place an ellipse.
I have WPF window with several textboxes, buttons, and canvas where I draw a
I have several wpf pages with update/delete/add buttons. I want to display to the
I have a WPF control, that has a list of Investors, and in the
I have a WPF ListView that is bound to a BindingList<T>. The binding works
I have a WPF application in which I'm moving data around on a Canvas.
I have a custom WPF Line, that I whant to change the Style when

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.