0

Currently I am working on wpf popup which contains a label, which constitute of textblocks inside the control template. Here my issue is that popup has a bottom border shadow. Already a border is there for the popup along with that this shadow effect increases the bottom border thickness, which looks like this (check the link below to see the screenshot for popup).

Wpf code is like this

Label Control template style

     <Style x:Key="popuplabelstyle" TargetType="{x:Type Label}">
            <Setter Property="OverridesDefaultStyle" Value="true" />        
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Label}">
                        <Border BorderBrush="Red" x:Name="labelBorder"   BorderThickness="1" Padding="12" Background="White" Height="auto" MinHeight="260" Width="220">
                            <StackPanel>
                                <TextBlock Text="ABCD" Margin="0,0,0,4" />
                                <TextBlock Text="abcd" Margin="0,4,0,0" />
                            </StackPanel>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

xaml code for popup

<Popup x:Name="Mypopup" Panel.ZIndex="2" Placement="MousePoint"  HorizontalOffset="10" VerticalOffset="10" IsOpen="{Binding ">
<Label Style="{StaticResource popuplabelstyle}"/>
</Popup>

I don't know why it's happening like this. Can anyone help me to solve this?

See the screenshot of the popup in below link

mm8
  • 163,881
  • 10
  • 57
  • 88
SHK
  • 135
  • 3
  • 13

1 Answers1

0

Try to set the SnapsToDevicePixels and/or UseLayoutRounding property of the Border to True to enable pixel snap rendering:

<ControlTemplate TargetType="{x:Type Label}">
    <Border BorderBrush="Red" x:Name="labelBorder"  
                                BorderThickness="1" Padding="12" Background="White" Height="auto" MinHeight="260" Width="220"
                                SnapsToDevicePixels="True" UseLayoutRounding="True">
        <StackPanel>
            <TextBlock Text="ABCD" Margin="0,0,0,4" />
            <TextBlock Text="abcd" Margin="0,4,0,0" />
        </StackPanel>
    </Border>
</ControlTemplate>

This should make the Border look sharper.

When should I use SnapsToDevicePixels in WPF 4.0?

Community
  • 1
  • 1
mm8
  • 163,881
  • 10
  • 57
  • 88