当前位置:网站首页>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; }
}
}
效果
边栏推荐
- Power button (LeetCode) 212. The word search II (2022.07.31)
- 初识shell脚本
- typescript23-tuple
- Selenium:上传、下载文件
- 万字逐行解析与实现Transformer,并进行德译英实战(一)
- Robot_Framework:常用内置关键字
- (2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
- USB3.0:VL817Q7-C0的LAYOUT指南(二)
- High Numbers | 【Re-integration】Line Area Score 880 Examples
- 数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
猜你喜欢
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
基于Arduino制作非接触式测温仪
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
USB3.0:VL817Q7-C0的LAYOUT指南(二)
API设计笔记:pimpl技巧
typescript22-接口继承
typescript21 - Comparison of Interfaces and Type Aliases
类神经网络训练不起来怎么办
C# | 使用Json序列化对象时忽略只读的属性
2022年超全的Android面经(附含面试题|进阶资料)
随机推荐
USB3.0:VL817Q7-C0的LAYOUT指南(二)
state compressed dp
Immutable
Selenium:元素等待
6-23漏洞利用-postgresql代码执行利用
MySQL-Data Definition Language-DDLdatebase define language
数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
「以云为核,无感极速」顶象第五代验证码
Selenium:鼠标、键盘事件
Robot_Framework:常用内置关键字
UE4 rays flashed from mouse position detection
4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
Selenium:操作Cookie
II. Binary tree to Offer 68 - recent common ancestor
可持久化线段树
Selenium:上传、下载文件
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
在沈自所的半年总结
pytorch、tensorflow对比学习—张量
风险策略调优中重要的三步分析法