views:

1843

answers:

2

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

A: 

You can force the application to use the vista theme (aero)

Open your app.xaml and put something like:

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/aero.normalcolor.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

Don't forget to put the PresentationFramework.Aero reference into your project.

With this, you will se you application in XP like in Vista.

Jesus Rodriguez
A: 

Hmm... are you running into a focus issue? I loaded the Aero theme, and I'm seeing your TextBox inset when the TextBox has focus or is moused-over. You can see this pretty clearly when you add a second TextBox like so:

<DockPanel Margin="15">
 <TextBox BorderThickness="1" BorderBrush="#FF000000"></TextBox>
 <TextBox BorderThickness="1" BorderBrush="#FF000000"></TextBox>
</DockPanel>

The default Style for Aero uses a ControlTemplate which sets the TextBox's border to use the ListBoxChrome which looks to set some extra properties when the control has Focus or is moused over.

Alternately, the default Style for the Luna theme binds the containing Border's BorderBrush directly to the TemplateBinding, which means that this is always respected (and why it works in XP/Luna and not in 2008 or Vista).

micahtan
If I apply the Aero theme as above, then the behavior you describe is dead on.However, without that theme, then I see the issue originally described.
CitizenParker