C# WPF编程-边框控件(Border)

C# WPF编程-边框控件(Border)

WPF中的Border控件。在WPF中,Border是一个非常有用的控件,它可以用于为其他控件或容器添加边框和背景。Border只能包含一个子元素,但这个子元素可以是另一个容器(如Grid, StackPanel, 等),从而间接地允许对多个控件应用相同的边框效果。

属性说明:

  • BorderBrush:定义边框的颜色。
  • BorderThickness:定义边框的厚度。可以设置为统一值(例如"2")或分别指定四个方向的厚度(例如"左,上,右,下")。
  • CornerRadius:使边框的角变圆。如果设置了此属性,则边框的四个角将变为圆角。
  • Background:可选属性,用于设置Border的背景颜色或图案。
xml 复制代码
<Window x:Class="WpfBaseDemo.WindowBorderDemo"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfBaseDemo"
        mc:Ignorable="d"
        Title="WindowBorderDemo" Height="450" Width="800">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <Border Grid.Row="0" Grid.Column="0" BorderThickness="3" BorderBrush="Green" Background="LightYellow" CornerRadius="10" >
            <TextBlock Text="圆角边框文本框" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="Blue" FontWeight="ExtraBold"/>
        </Border>

        <Border Grid.Row="0" Grid.Column="1" BorderThickness="3" BorderBrush="Red" Background="DarkCyan" CornerRadius="50">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock>文本框</TextBlock>
                <Button>按钮控件</Button>
                <ProgressBar Height="20" Width="100" Value="30"/>
            </StackPanel>
        </Border>

        <Border Grid.Row="1" Grid.Column="0" BorderThickness="20" BorderBrush="Blue" CornerRadius="100" Background="LightBlue">
            <TextBlock Text="边框控件" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        </Border>

        <Border Grid.Row="1" Grid.Column="1" BorderThickness="5" BorderBrush="DarkBlue" Background="LightBlue" CornerRadius="0 10 20 40">
            <TextBlock Text="指定4角圆角不同半径" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="DarkGreen" FontSize="20"/>
        </Border>
    </Grid>
</Window>
相关推荐
SmartRadio6 分钟前
MK8000(UWB射频芯片)与DW1000的协议适配
c语言·开发语言·stm32·单片机·嵌入式硬件·物联网·dw1000
guygg887 分钟前
基于捷联惯导与多普勒计程仪组合导航的MATLAB算法实现
开发语言·算法·matlab
froginwe1122 分钟前
Rust 文件与 IO
开发语言
liulilittle24 分钟前
LIBTCPIP 技术探秘(tun2sys-socket)
开发语言·网络·c++·信息与通信·通信·tun
yyy(十一月限定版)25 分钟前
c++(3)类和对象(中)
java·开发语言·c++
落羽凉笙27 分钟前
Python基础(4)| 玩转循环结构:for、while与嵌套循环全解析(附源码)
android·开发语言·python
ytttr87330 分钟前
MATLAB的流体动力学与热传导模拟仿真实现
开发语言·matlab
码农学院32 分钟前
使用腾讯翻译文本
服务器·数据库·c#
山上三树33 分钟前
详细介绍 C 语言中的 #define 宏定义
c语言·开发语言·算法
测试游记41 分钟前
基于 FastGPT 的 LangChain.js + RAG 系统实现
开发语言·前端·javascript·langchain·ecmascript