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

边栏推荐
- The Flow Of Percona Toolkit pt-table-checksum
- 请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?
- Code Interview Guide for Programmers CD15 Generating an Array of Windowed Maximums
- 请求/响应拦截器写法
- HJS-DE1/2时间继电器
- typescript25-类型断言
- typescript28 - value of enumeration type and data enumeration
- 万字逐行解析与实现Transformer,并进行德译英实战(二)
- SL-12/2过流继电器
- Immutable
猜你喜欢

(2022 Nioke Duo School IV) D-Jobs (Easy Version) (3D prefix or)

typescript27 - what about enumeration types

pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)

typescript24 - type inference

PaddleX部署推理模型和GUI界面测试结果不一致的解决方法

Excel record of integer programming optimization model to solve the problem

Pyspark Machine Learning: Vectors and Common Operations

typescript21-接口和类型别名的对比

Logitech Mouse Experience Record

II. Binary tree to Offer 68 - recent common ancestor
随机推荐
Immutable
状态压缩dp
Pyspark机器学习:向量及其常用操作
pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)
TIM登陆时提示00001(TIM00001)
y83.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十四)
pytorch、tensorflow对比学习—张量
基于Arduino制作非接触式测温仪
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
高数 | 【重积分】线面积分880例题
typescript21-接口和类型别名的对比
【目标检测】YOLOv7理论简介+实践测试
The Flow Of Percona Toolkit pt-table-checksum
FFmpeg 搭建本地屏幕录制环境
干货!如何使用仪表构造SRv6-TE性能测试环境
RSA主要攻击方法
Selenium:简介
API Design Notes: The pimpl trick
typescript28 - value of enumeration type and data enumeration
Selenium:元素等待