C#WPF基础01

C#WPF基础01

wpf

微软推出的基于Windows 的用户界面框架,属于.NET Framework 3.0的一部分。它提供了统一的编程模型、语言和框架。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-coZTWrtN-1597325907603)(C:\Users\TR\AppData\Roaming\Typora\typora-user-images\image-20200729083134289.png)]

通过触发事件调用方法,由系统触发事件并调用。也可以让多个事件调用同一个方法。在删除事件时,需要删除事件调用的方法,还需要删除xml里面的对应的事件的代码。

sender

是指调用该方法的控件,是触发该事件的控件。

复习继承

变量是一个标签,对象是一个实际存在的东西,其实就是在给实在的东西贴标签。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SYymwsUr-1597325907607)(C:\Users\TR\AppData\Roaming\Typora\typora-user-images\image-20200729091254797.png)]

Xmal文件的格式

语法格式与HTML类似。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2r570cND-1597325907609)(C:\Users\TR\AppData\Roaming\Typora\typora-user-images\image-20200729092849761.png)]

<Window x:Class="day24test02.MainWindow"
        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:day24test02"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        //简单属性的写法
        <Button Content="111" Width="80" Background="AliceBlue">
            //使用与复杂属性的写法,写在对应控件的里面
            <Button.Height>60</Button.Height>
        </Button>
        //margin 
        <TextBox Text="222" Width="100" Height="30" Margin="100 300 300 100"></TextBox>
        
    </Grid>
</Window>

控件常用通用属性

visibility 控件是否可见(所有控件均有该属性) 有两个选项值collapsed 不可见 visible 可见

isenabled 控件是否可用()bool值

background 背景色,多个选择

foreground 前景色,文本类控件

fontsize 字体大小,文本类控件

text 文本控件的显示内容

isreadonly 是否只读(允许修改)

textwarpping 单多行文本框(warp多行 nowarp单行文本框)

maxlength 文本内可以键盘输入的最多字符

HorizontalAlignment 水平对齐

VerticalAlignment 垂直分布

密码框控件——passwordbox

password 显示内容

passwordChar 密码框内的内容以指定字符的形式显示

可空的数据类型

所有的引用类型都可以为null值。值类型一般情况下不能为null,但int?则可以赋null值。

不能把int? 赋值给 int,可以将int 赋值给 int?。可以通过(int)强制转换保证编译不出错,但是会在运行时抛出异常。

常用控件

radiobutton

单选按钮,通过groupname组名的方式来给按钮分组。

Datepicker

日期选择器,文本内容通过selecteddate(选中日期)属性实现。

Image

图片控件,source图片相对路径。

Image image = new Image();
                    image.Source = new BitmapImage(new Uri($"img/{n}.jpg", UriKind.Relative));
progressbar

进度框,显示进度。mininum 最小值 maxinum 最大值 value 当前值

isindeterminate 是否不确定模式

StackPanel布局

默认是一种从上往下,可以更改从左往右的布局模式。

Orientation horizontal 左往右 的布局

rivate void Button_Click(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < 10; i++)
            {
                Button ntn = new Button();
                //Label lal = new Label();
                ntn.Height = 20;
                ntn.Content = "a";
                ntn.Visibility = Visibility.Visible;
                //必须要在布局内添加要增加的控件
                sp1.Children.Add(ntn);
                
            }
        }
<Window x:Class="day24test07.MainWindow"
        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:day24test07"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <StackPanel Name="sp1">
            <Button Content="1"></Button>
            <Button Content="2"></Button>
            <Button>
            //通过这种方式可以在content中添加多个内容
                <Button.Content>
                    <StackPanel Orientation="Horizontal">
                        <TextBox Text="12"></TextBox>
                        <Label Content="3"></Label>
                    </StackPanel>
                </Button.Content>
            </Button>
            <Button Content="4"></Button>
            <Button Content="5" Click="Button_Click"></Button>
        </StackPanel>
    </Grid>
</Window>
grid布局

Grid.Column 确定位于哪一列

Grid.Row 确定位于哪一行

Grid.RowSpan 确定控件占几行

Grid.ColumnSpan 确定控件占几列

<Window x:Class="day24test08.MainWindow"
        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:day24test08"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.ColumnDefinitions>	//列
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>		//行
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Button Grid.Column="1" Grid.Row="1"></Button>
    </Grid>
</Window>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Echo_Wish

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值