wpf - 为什么 WPF Border 的 "Border"在设计模式下可见,但在应用程序中却看不到?

标签 wpf

enter image description here

设计器在红色背景周围显示了黑色边框,但实际应用程序只显示红色背景。是什么赋予了?如何强制显示黑色边框?

这是此窗口的 XAML:

<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>

最佳答案

我的猜测是运行时边框的默认厚度为 0 - 可能是因为应用程序资源字典中的继承样式。从全局资源字典继承的默认样式通常不会在设计时显示。

尝试显式设置 BorderThickness="1"

关于wpf - 为什么 WPF Border 的 "Border"在设计模式下可见,但在应用程序中却看不到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10076497/

相关文章:

wpf - 如何减少 RadioButton 绑定(bind)代码?

wpf - 更新 wpf 数据网格的 SelectedeRow 值的 GUI

wpf - WPF 中类似 global.asax 的东西

c# - MVVM 关闭文档的方式可以取消

C# WPF - 自定义调整大小

WPF DataGrid - 使用复选框隐藏列

c# - MVVM 结构 : Where does sending a file to a server go in MVVM?

c# - 从 DataGrid WPF C# 中的选定行获取特定单元格的数据

wpf - 更改 TabItem 的标题字体粗细

c# - 使用 BeginInvoke 动态添加 ListView 项时出现 "The calling thread must be STA, because many UI components require this."