views:

1442

answers:

4
+1  A: 

WPF tries to be device independent when rendering UI to the monitor, and won't draw things "pixel perfect" unless you tell it to. Try adding this to your style:

<Setter Property="SnapsToDevicePixels" Value="True" />

That should tell WPF to render each 1-pixel-thick border along a single pixel line.

Matt Hamilton
I tried without success :-( Those TextBoxes are placed in a Grid. Could it be a problem? But for majority of TextBoxes I set Width="Auto" or Width="*" .. so I don't see the point of hiding.
PaN1C_Showt1Me
Hmm. Having the TextBoxes in a grid shouldn't be a problem. Can you update your question with the complete style definition?
Matt Hamilton
Yes of course. I edited my post.
PaN1C_Showt1Me
A: 

You need do the followings to solve that problem...

  1. SnapsToDevicePixels="True"
  2. Dont specify width, do it with the margins

    <Setter Property="BorderBrush" HorizontalAlignment="Left" Margin="2,2,2,2" Value="{StaticResource DarkGray}" />

Hope this helps :)

Prashant
Hmm. I've already tried everything. I think that the problem ought be somewhere else.
PaN1C_Showt1Me
A: 

I think that the left border and upper border is styled, but the right and buttom border stays gray, although I explicitly said in Style that BorderBrush=MyBrush. What do you think? What about to try remove the 3D effect from TextBox?

PaN1C_Showt1Me
Try reducing the textbox width and height... observe any changes
Prashant
+2  A: 

You could try editing the template for the textboxes and changing the border name Bd to a "real" border instead of the chrome one. Like this:

<ControlTemplate x:Key="TextBoxBaseControlTemplate1" 
          TargetType="{x:Type TextBoxBase}">
  <Border x:Name="Bd" SnapsToDevicePixels="True" 
          Background="{TemplateBinding Background}" 
          BorderBrush="{TemplateBinding BorderBrush}"
          BorderThickness="{TemplateBinding BorderThickness}" >
    <ScrollViewer x:Name="PART_ContentHost" 
              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
  </Border>
  <ControlTemplate.Triggers>
    <Trigger Property="IsEnabled" Value="False">
      <Setter Property="Background" TargetName="Bd" 
            Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
      <Setter Property="Foreground" 
           Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    </Trigger>
  </ControlTemplate.Triggers>
</ControlTemplate>

add this setter to your style to enable the template:

<Setter Property="Template" 
        Value="{DynamicResource TextBoxBaseControlTemplate1}"/>
Sorskoot
Thank you very much. Finally a working solution ! U rock man!
PaN1C_Showt1Me