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>
相关推荐
老师我太想进步了20263 分钟前
C语言版讲解函数递归
c语言·开发语言
猿长大人21 分钟前
C# | 函数式编程入门
开发语言·c#·.net
W_3260024 分钟前
Python 组合数据类型——序列(列表 & 元组)
开发语言·python
Billy1213830 分钟前
Day10-C++20 Ranges(上):惰性求值与组合式数据处理
开发语言·c++进阶学习
有点。44 分钟前
C++深度优先搜索(二)
开发语言·c++·深度优先
二进制杯莫停1 小时前
A和B环境的python版本相同,B环境无法安装pip依赖,离线安装
开发语言·python·pip
l1t1 小时前
kryonix提交的DuckDB 统一并优化标量执行器基础设施 - #24564 PR
开发语言·数据库·数据仓库·sql
unityのkiven2 小时前
C# 中的奇异递归模板模式:MonoSingleton<T> 的实现
java·开发语言·c#
雪隐2 小时前
WPF + MVVM 实战系列02-告别 INPC 手写时代,做个体面的现代 WPF 人
前端·后端·c#
就不掉头发3 小时前
C++函数模板
java·开发语言·c++