当前位置:网站首页>WPF项目-初步了解数据绑定 binding
WPF项目-初步了解数据绑定 binding
2022-08-01 05:07:00 【济南医疗小程序状元】
初级入门数据绑定案例
<Window x:Class="WpfApp1.Data数据绑定.Windowdata"
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:WpfApp1.Data数据绑定"
xmlns:s="clr-namespace:WpfApp1.Entity"
mc:Ignorable="d"
Title="Windowdata" Height="450" Width="800">
<Grid>
<Grid.Resources>
<!--d
这是个资源字典
key 为 MydataSource
value 为 Mydata类 C#
-->
<s:Mydata x:Key="mydataSource"/>
</Grid.Resources>
<Grid.DataContext>
<Binding Source="{StaticResource mydataSource}"/>
</Grid.DataContext>
<!--1 按钮进行了一个绑定,都是有迹可循的。
-->
<Button Background="{Binding Path=ColorName}"
Width="{Binding Path=Width}" Height="30">
</Button>
</Grid>
</Window>
C# 类代码 点击事件
using System;
using System.Collections.Generic;
using System.Text;
namespace WpfApp1.Entity
{
public class Mydata
{
private string colorName = "green";
private int width = 500;
/// <summary>
/// 这样子colorName的属性的默认值就是 "red”
/// </summary>
// 属性首字母大写啊
public string ColorName { get => colorName; set => colorName = value; }
public int Width { get => width; set => width = value; }
}
}
效果
边栏推荐
- Excel record of integer programming optimization model to solve the problem
- 请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
- typescript21-接口和类型别名的对比
- PMP 相关方管理必背总结
- The method of solving stored procedure table name passing through variable in mysql
- typescript25-类型断言
- typescript28-枚举类型的值以及数据枚举
- Pyspark Machine Learning: Vectors and Common Operations
- ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
- 在互联网时代,有诸多「互联网+」模式的诞生
猜你喜欢
y83.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十四)
剑指 Offer 68 - II. 二叉树的最近公共祖先
MySQL-DML语言-数据库操作语言-insert-update-delete-truncate
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
typescript27 - what about enumeration types
Risk strategy important steps of tuning method
数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
pytroch、tensorflow对比学习—专栏介绍
The method of solving stored procedure table name passing through variable in mysql
I met a shell script
随机推荐
(more than 2022 cattle school four) A - Task Computing + dynamic programming (sort)
Li Chi's work and life summary in July 2022
解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
7 行代码搞崩溃 B 站,原因令人唏嘘!
华为Android开发面试后得出的面试秘诀
MySQL Practice Summary -
Selenium:鼠标、键盘事件
The Principle Of Percona Toolkit Nibble Algorithm
typescript28-枚举类型的值以及数据枚举
6-23漏洞利用-postgresql代码执行利用
[MySQL] 多表查询
Robot_Framework:断言
typescript25 - type assertion
typescript28 - value of enumeration type and data enumeration
4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
typescript23-tuple
MySQL实践总结-
USB3.0:VL817Q7-C0的LAYOUT指南(三)
typescript21 - Comparison of Interfaces and Type Aliases
【云原生之kubernetes实战】kubernetes集群的检测工具——popeye