当前位置:网站首页>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; }
}
}
效果
边栏推荐
猜你喜欢
2022年超全的Android面经(附含面试题|进阶资料)
SL-12/2过流继电器
这里有110+公开的专业数据集
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Robot_Framework:断言
UE4 制作遇到的问题
华为Android开发面试后得出的面试秘诀
产品经理访谈 | 第五代验证码的创新与背景
Excel做题记录——整数规划优化模型
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
随机推荐
MySQL-DML语言-数据库操作语言-insert-update-delete-truncate
剑指 Offer 68 - II. 二叉树的最近公共祖先
MySQL-数据操作-分组查询-连接查询-子查询-分页查询-联合查询
Excel做题记录——整数规划优化模型
零序电流继电器器JL-8C-12-2-2
2022年超全的Android面经(附含面试题|进阶资料)
I met a shell script
7月编程排行榜来啦!这次有何新变化?
Selenium:元素定位
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
pytorch、tensorflow对比学习—计算图和微分机制
PMP 相关方管理必背总结
Code Interview Guide for Programmers CD15 Generating an Array of Windowed Maximums
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
Selenium:简介
MySQL-Data Operation-Group Query-Join Query-Subquery-Pagination Query-Joint Query
PMP子过程定义总结
6-23漏洞利用-postgresql代码执行利用
PAT class B 1001 (3n+1) conjecture
PaddleX部署推理模型和GUI界面测试结果不一致的解决方法