WPF Textbox & Borders - curious resizing behavior

Posted by CitizenParker on Stack Overflow See other posts from Stack Overflow or by CitizenParker
Published on 2009-06-15T19:00:18Z Indexed on 2012/09/30 9:37 UTC
Read the original article Hit count: 390

Filed under:
|
|
|

The following XAML produces a window with strange behavior around the textbox:

<Window x:Class="WpfSandbox.CuriousExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CuriousExample" Height="300" Width="300">
    <DockPanel Margin="15">
        <TextBox BorderThickness="1" BorderBrush="#FF000000"></TextBox>
    </DockPanel>
</Window>

What happens, at least during my limited testing, is that the textbox renders with an inset border pattern (top/left is black, right/bottom is grey). However, when you resize to any position except the original, the entire textbox border goes to black. Whenever you return the window to the exact number of on-screen pixels the form had when it first loaded, it's inset again.

I'm guessing it isn't pixel snapping as I can easily correct the problem with this code:

<Window x:Class="WpfSandbox.CuriousExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CuriousExample" Height="300" Width="300">
    <DockPanel Margin="15">
        <Border BorderThickness="1" BorderBrush="#FF000000">
            <TextBox BorderThickness="0" ></TextBox>
        </Border>
    </DockPanel>
</Window>

Anyone care to venture an explanation as to what I'm seeing? Or is it all in my head?

Like I said, the above workaround can resolve this problem - just trying to understand what is happening here.

Thanks,

-Scott

© Stack Overflow or respective owner

Related posts about wpf

Related posts about textbox