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

边栏推荐
猜你喜欢

typescript23-元组

华为Android开发面试后得出的面试秘诀

【目标检测】YOLOv7理论简介+实践测试

typescript26-字面量类型

NDK does not contain any platforms问题解决

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

II. Binary tree to Offer 68 - recent common ancestor

(2022牛客多校四)H-Wall Builder II(思维)

罗技鼠标体验记录

typescript20-接口
随机推荐
typescript23-tuple
LeetCode 1189. “气球” 的最大数量
(Codeforce 757)E. Bash Plays with Functions(积性函数)
MySQL-数据定义语言-DDLdatebase define language
High Numbers | 【Re-integration】Line Area Score 880 Examples
【目标检测】YOLOv7理论简介+实践测试
「以云为核,无感极速」顶象第五代验证码
Power button (LeetCode) 212. The word search II (2022.07.31)
7月编程排行榜来啦!这次有何新变化?
(2022牛客多校四)N-Particle Arts(思维)
Selenium:简介
用控件当画笔获得bitmap代码记录
力扣(LeetCode)212. 单词搜索 II(2022.07.31)
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
typescript24-类型推论
typescript27-枚举类型呢
Error: AttributeError: module 'matplotlib' has no attribute 'figure'
PMP工具与技术总结
挑战52天背完小猪佩奇(第01天)
请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?