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 413865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:13:35+00:00 2026-05-12T18:13:35+00:00

I’m using the WPF Grid to align objects, and ran into a rather glaring

  • 0

I’m using the WPF Grid to align objects, and ran into a rather glaring issue regarding pixel alignment of columns. I tried to remove as many variables as possible, and managed to show the issue in this code:

<Window x:Class="Test.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">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100.5" />
        <ColumnDefinition Width="199.5" />
    </Grid.ColumnDefinitions>
    <Border Background="Red">
        <Grid.Column>1</Grid.Column>
    </Border>
    <Border Background="Red">
    </Border>
</Grid>
</Window>

If you run that sample, it’s easy to see that there’s an issue in the border between the two columns. It’s caused, I believe, because WPF simply alpha-blends one column with the background and the other with the result, even though conceptually both columns are in the same Z, so the pixel should be the blending of the sum of their weights and the background.

I understand this is a problematic issue, and naturally I don’t intentionally create columns with partial pixel sizes, but the same effect can be easily observed when using star sizes (which I do use a lot).

This issue can be worked around by using the SnapsToDevicePixels property (<Grid SnapsToDevicePixels="True"> instead of <Grid>). this works because WPF has internally-consistent rounding, so both columns snap to the same pixel.
However, I hit a related problem which is very similar in vein, to which I couldn’t find a solution.

For some reason, when using the Geometry class, I get the same sort of pixel alignment issues, and I this time I didn’t find any sort of work-around. It’s as if the pixels are rounded, but now the Geometry is snapped one pixel off, leaving a hole 1-pixel-wide hole.

Example code:

<Window x:Class="Test.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">
<Grid SnapsToDevicePixels="False">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100.5" />
        <ColumnDefinition Width="199.5" />
    </Grid.ColumnDefinitions>
    <Border Background="Red">
        <Grid.Column>1</Grid.Column>
    </Border>
    <Border>
        <Border.Background>
            <DrawingBrush>
                <DrawingBrush.Drawing>
                    <GeometryDrawing Brush="Red">
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0,0,1,1"></RectangleGeometry>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingBrush.Drawing>
            </DrawingBrush>
        </Border.Background>
    </Border>
</Grid>
</Window>

Any idea how to get my pixels aligned properly?

EDIT:

Working correctly now after adding a GuidelineSet according to the answer. Working drawing code is:

<DrawingGroup>
    <DrawingGroup.GuidelineSet>
        <GuidelineSet GuidelinesX="0,1" GuidelinesY="0,1"></GuidelineSet>
    </DrawingGroup.GuidelineSet>                
    <GeometryDrawing Brush="Red">
        <GeometryDrawing.Geometry>
            <RectangleGeometry Rect="0,0,1,1"></RectangleGeometry>
        </GeometryDrawing.Geometry>
    </GeometryDrawing>
</DrawingGroup>
  • 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-12T18:13:35+00:00Added an answer on May 12, 2026 at 6:13 pm

    I believe you must use a GuidelineSet in the case of a Drawing. There’s a good section on how to apply GuidelineSets available here in the SDK.

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

Sidebar

Ask A Question

Stats

  • Questions 209k
  • Answers 209k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer before_update :set_instock, :unless => :inventory_not_needed? private def set_instock self.instock =… May 12, 2026 at 9:51 pm
  • Editorial Team
    Editorial Team added an answer A branch or a tag in subversion is basically a… May 12, 2026 at 9:51 pm
  • Editorial Team
    Editorial Team added an answer FWIW, I think this question should be posed on serverfault.com… May 12, 2026 at 9:51 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.