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>
相关推荐
小小龙学IT几秒前
simdjson:利用 SIMD 指令实现 GB/s 级 JSON 解析的 C++ 开源库
开发语言·c++·json
A_nanda10 分钟前
c#WPF开发常见问题
开发语言·c#·wpf
唐青枫11 分钟前
别只会解析参数:C#.NET Spectre.Console.Cli 命令行工具实战详解
c#·.net
Hello.Reader26 分钟前
REALITY 技术深度解析从 TLS 伪装、抗主动探测到 VLESS + XTLS Vision 完整实践
开发语言·php
不正经学生34 分钟前
C语言字符串函数进阶:安全版函数 + 错误处理 + 子串查找
c语言·开发语言·c++·算法·面试
ITKEY_1 小时前
neovim基于nvim-jdtls 开发java报错
java·开发语言
無限進步D1 小时前
Java 代码块
java·开发语言
吃好睡好便好1 小时前
MATLAB仿真框图4
开发语言·matlab·仿真·分段函数
TheBestRucy1 小时前
基于Dify的旅游攻略&王者荣耀攻略智能助手项目
服务器·开发语言·人工智能·python·算法·旅游
一水1 小时前
Pi :内置四工具源码拆解——文件锁、变更快照与 bash 隔离
开发语言·chrome·ai·bash