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

边栏推荐
- 报错:AttributeError: module ‘matplotlib’ has no attribute ‘figure’
- Typescript22 - interface inheritance
- Excel record of integer programming optimization model to solve the problem
- Selenium:上传、下载文件
- 2022年超全的Android面经(附含面试题|进阶资料)
- USB3.0:VL817Q7-C0的LAYOUT指南(三)
- 备战金九银十,如何顺利通过互联网大厂Android的笔面试?
- (2022牛客多校四)A-Task Computing (排序+动态规划)
- Selenium:表单切换
- typescript26-字面量类型
猜你喜欢

Selenium:操作Cookie

Robot_Framework:关键字

初识shell脚本

(2022牛客多校四)D-Jobs (Easy Version)(三维前缀或)

pytorch、tensorflow对比学习—功能组件(优化器、评估指标、Module管理)

(2022牛客多校四)K-NIO‘s Sword(思维)

USB3.0:VL817Q7-C0的LAYOUT指南(三)

Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers

pytroch、tensorflow对比学习—使用GPU训练模型

6-23漏洞利用-postgresql代码执行利用
随机推荐
请问shake数据库中想把源的db0的数据同步到目的db5,参数怎么设置呢?
25. 这三道常见的面试题,你有被问过吗?
文件的异步读写
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
(2022牛客多校四)A-Task Computing (排序+动态规划)
UE4 制作遇到的问题
Selenium:简介
Code Interview Guide for Programmers CD15 Generating an Array of Windowed Maximums
PAT乙级 1002 写出这个数
PAT class B 1001 (3n+1) conjecture
数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
万字逐行解析与实现Transformer,并进行德译英实战(二)
PaddleX部署推理模型和GUI界面测试结果不一致的解决方法
vim配置+ctag像source insight一样方便阅读代码
在互联网时代,有诸多「互联网+」模式的诞生
程序员代码面试指南 CD15 生成窗口最大值数组
Excuse me, only primary key columns can be queried using sql in table storage. Does ots sql not support non-primary keys?
用控件当画笔获得bitmap代码记录
typescript22-接口继承
Optional parameters typescript19 - object