当前位置:网站首页>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; }
}
}
效果

边栏推荐
- (2022牛客多校四)D-Jobs (Easy Version)(三维前缀或)
- 请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
- 4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
- Excel record of integer programming optimization model to solve the problem
- 剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
- typescript26 - literal types
- typescript22-接口继承
- Selenium:操作Cookie
- typescript24 - type inference
- The Principle Of Percona Toolkit Nibble Algorithm
猜你喜欢
随机推荐
Robot_Framework:断言
Error: AttributeError: module 'matplotlib' has no attribute 'figure'
mysql中解决存储过程表名通过变量传递的方法
SL-12/2过流继电器
律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性
LeetCode 387. 字符串中的第一个唯一字符
Risk strategy important steps of tuning method
冲刺金九银十,Android开发面试(内含面试资料|面试题|源码)
pytorch、tensorflow对比学习—功能组件(优化器、评估指标、Module管理)
(Codeforce 757) E. Bash Plays with Functions
Optional parameters typescript19 - object
Selenium:操作JS
PAT乙级 1001 害死人不偿命的(3n+1)猜想
程序员代码面试指南 CD15 生成窗口最大值数组
7 行代码搞崩溃 B 站,原因令人唏嘘!
DL-31/6电流继电器
UE4 模型OnClick事件不生效的两种原因
USB3.0:VL817Q7-C0的LAYOUT指南(三)
Selenium:弹窗处理
「以云为核,无感极速」顶象第五代验证码









