
The designer shows a black border around the red background, but the actual application only shows the red background. What gives? How to force the black border to be visible?
Here’s the XAML for this window:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
MinWidth="400" MinHeight="300"
TextOptions.TextFormattingMode="Display">
<DockPanel Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<Button DockPanel.Dock="Top" Content="A button"
Padding="8,2" Margin="8" />
<Border DockPanel.Dock="Top" Height="10" BorderBrush="Black"
SnapsToDevicePixels="True" Background="Red" />
<Button DockPanel.Dock="Top" Content="A button"
Padding="8,2" Margin="8" />
</DockPanel>
</Window>
My guess is that the default thickness of the border during runtime is 0 – possibly because of an inherited style in the application resource dictionary. Default styles inherited from a global resource dictionary often don’t show up during design time.
Try explicitly setting the
BorderThickness="1"