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

边栏推荐
- 请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?
- LeetCode 9. 回文数
- Optional parameters typescript19 - object
- (2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
- 罗技鼠标体验记录
- 56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
- Selenium:浏览器操作
- High Numbers | 【Re-integration】Line Area Score 880 Examples
- typescript26 - literal types
- pytroch、tensorflow对比学习—专栏介绍
猜你喜欢

Visual Studio提供的 Command Prompt 到底有啥用

(2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)

state compressed dp

MySQL-数据定义语言-DDLdatebase define language

高数 | 【重积分】线面积分880例题

(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)

UE4 制作遇到的问题

The method of solving stored procedure table name passing through variable in mysql

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

pytroch、tensorflow对比学习—专栏介绍
随机推荐
typescript23-tuple
高数 | 【重积分】线面积分880例题
Selenium:操作JS
ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
ModuleNotFoundError: No module named ‘tensorflow.keras‘报错信息的解决方法
零序电流继电器器JL-8C-12-2-2
typescript25 - type assertion
typescript25-类型断言
LeetCode 9. 回文数
typescript23-元组
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Typescript22 - interface inheritance
typescript19-对象可选参数
typescript26-字面量类型
typescript28 - value of enumeration type and data enumeration
Risk strategy important steps of tuning method
typescript27 - what about enumeration types
剑指 Offer 68 - II. 二叉树的最近公共祖先
可持久化线段树
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先