Why are WPF Border borders visible in design mode but not in the application?

        enter image description here

The designer shows a black border around the red background, but the actual app only shows the red background. What gives? How do I make the black border visible?

Here's the XAML for that 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>

      

+3


source to share


3 answers


My guess is that the default border thickness at runtime is 0 - possibly due to an inherited style in the app's resource dictionary. Default styles inherited from the global resource dictionary are often not displayed at design time.



Try to explicitly set BorderThickness="1"

+3


source


I'm not sure why the border is showing in design mode, but you can show it in the app by adding an explicit thickness



<Border DockPanel.Dock="Top" Height="10" BorderBrush="Black"
        SnapsToDevicePixels="True" Background="Red" BorderThickness="1" />

      

+3


source


        <Border.BorderBrush>
            <SolidColorBrush Color="{DynamicResource Gray4}"/>
        </Border.BorderBrush>

      

Replace the value of the "Color" property using hex:

        <Border.BorderBrush>
            <SolidColorBrush Color="#FFD33B3B"/>
        </Border.BorderBrush>

      

0


source







All Articles