当前位置: 首页 > news >正文

求一个做美食视频的网站陕西手机网站建设

求一个做美食视频的网站,陕西手机网站建设,wordpress编辑器段间距,如何制作网站教程视频第7章#xff1a;数据绑定 本章目标 理解路由事件 掌握键盘输入事件 掌握鼠标输入事件 掌握多点触控输入事件 数据绑定概述 什么是数据绑定 ​ 将WPF中的至少一个带有依赖项属性的两个对象的两个属性进行绑定#xff0c;使某一个依赖项属性可以更新和它绑定的属性的功…第7章数据绑定 本章目标 理解路由事件 掌握键盘输入事件 掌握鼠标输入事件 掌握多点触控输入事件 数据绑定概述 什么是数据绑定 ​ 将WPF中的至少一个带有依赖项属性的两个对象的两个属性进行绑定使某一个依赖项属性可以更新和它绑定的属性的功能。 ​ 数据绑定涉及两个方面一个是绑定源再一个是绑定目标。绑定源即空间绑定所使用的源数据绑定目标即数据显示的控件。 对于绑定源在WPF中可以是以下4种 CLR对象可以绑定到CLR类的公开属性/子属性/索引器上ADO.net 对象例如DataTable/DataView 等。XML文件使用XPath 进行解析DependencyObject: 绑定到依赖项属性上即控件绑定控件。 对于绑定目标必须是WPF中的DependencyObject,将数据绑定到其依赖项属性上。 数据绑定的绑定源 使用接口 INoitfyPropertyChanged使用依赖属性 DependecyProperty 数据绑定的语法 {Binding ElementName元素名,Path属性,Mode绑定模式}绑定DependencyObject对象 根据元素名称绑定 Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledTitleMainWindow Height450 Width800StackPanelTextBox x:Nametxt1 TextWrappingWrap Height100/TextBoxTextBlock Text{Binding ElementNametxt1,PathText}/TextBlock/StackPanel/Window 相对于自身或父元素绑定 Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledTitleMainWindow Height450 Width800StackPanel Height150Button Height40 Content{Binding RelativeSource{RelativeSource ModeSelf},PathHeight} /Button Height40 Content{Binding RelativeSource{RelativeSource ModeFindAncestor, AncestorTypeStackPanel},PathHeight}//StackPanel/Window 绑定CLR对象 绑定到单个对象 xaml: Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledNamemainWindowTitleMainWindow Height450 Width800StackPanelLabel HorizontalAlignmentCenter FontSize20学生信息/LabelGridGrid.RowDefinitionsRowDefinition/RowDefinition/RowDefinition//Grid.RowDefinitionsGrid.ColumnDefinitionsColumnDefinition Width200/ColumnDefinition//Grid.ColumnDefinitionsLabel Grid.Row0 Grid.Column0 Content名字 HorizontalAlignmentRight/TextBox Grid.Row0 Grid.Column1 Text{Binding Name} /Label Grid.Row1 Grid.Column0 Content性别 HorizontalAlignmentRight/TextBox Grid.Row1 Grid.Column1 Text{Binding Sex} /Label Grid.Row2 Grid.Column0 Content年龄 HorizontalAlignmentRight/TextBox Grid.Row2 Grid.Column1 Text{Binding Age} //Grid/StackPanel /Window cs: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;namespace WPF_CH07_Demo01 {/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();//初始化数据Student student new Student() { Name 孙悟空, Sex 男, Age 18 };//指定数据上下文this.DataContext student;}}/// summary/// 学生类/// /summarypublic class Student{public string Name { get; set; }public string Sex { get; set; }public int Age { get; set; }} } 绑定到集合元素-1 xaml代码 Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledTitleMainWindow Height450 Width800StackPanelTextBlock姓名/TextBlockListBox ItemsSource{Binding NameList}/ListBox/StackPanel/Window cs代码 using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;namespace WPF_CH07_Demo01 {/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();//初始化数据this.NameList new ObservableCollectionstring();this.NameList.Add(孙悟空);this.NameList.Add(猪八戒);this.NameList.Add(沙悟净);//指定数据上下文this.DataContext this;}/// summary/// 姓名集合/// /summarypublic ObservableCollectionstring NameList { get; set; }} } 绑定到集合元素-2 xaml: Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledTitleMainWindow Height450 Width800StackPanelTextBlock学生/TextBlockListBox ItemsSource{Binding StuList}ListBox.ItemTemplateDataTemplateUniformGrid Columns3TextBlock Text{Binding Name} Margin5/TextBlock Text{Binding Sex} Margin5/TextBlock Text{Binding Age} Margin5//UniformGrid/DataTemplate/ListBox.ItemTemplate/ListBox/StackPanel/Window cs: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;namespace WPF_CH07_Demo01 {/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();//初始化数据this.StuList new ObservableCollectionStudent();this.StuList.Add(new Student { Name孙悟空,Sex男,Age150});this.StuList.Add(new Student { Name 猪八戒, Sex 男, Age 120 });this.StuList.Add(new Student { Name 沙悟净, Sex 男, Age 100 });//指定数据上下文this.DataContext this;}/// summary/// 姓名集合/// /summarypublic ObservableCollectionStudent StuList { get; set; }}/// summary/// 学生类/// /summarypublic class Student{/// summary/// 姓名/// /summarypublic string Name { get; set; }/// summary/// 性别/// /summarypublic string Sex { get; set; }/// summary/// 年龄/// /summarypublic int Age { get; set; }} } MVVM模式实现数据绑定 xaml: Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledTitleMainWindow Height450 Width800StackPanelTextBlock Text{Binding School} /TextBlock Text{Binding TeacherCount} /TextBlock Text{Binding StudentCount} //StackPanel /Window cs: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;namespace WPF_CH07_Demo01 {/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();//初始化数据MainViewModel mvm new MainViewModel();mvm.School 广创;mvm.TeacherCount 20;mvm.StudentCount 500;//指定数据上下文this.DataContext mvm;}}/// summary/// 页面视图 数据 模型/// /summarypublic class MainViewModel{/// summary/// 学校/// /summarypublic string School { get; set; }/// summary/// 教师人数/// /summarypublic int TeacherCount { get; set; }/// summary/// 学生人数/// /summarypublic int StudentCount { get; set; }} } 属性改变通知进行数据绑定 xaml: Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledNamemainWindowTitleMainWindow Height450 Width800StackPanelLabel HorizontalAlignmentCenter FontSize20学生信息/LabelGridGrid.RowDefinitionsRowDefinition/RowDefinition/RowDefinition/RowDefinition/RowDefinition//Grid.RowDefinitionsGrid.ColumnDefinitionsColumnDefinition Width200/ColumnDefinition//Grid.ColumnDefinitionsLabel Grid.Row0 Grid.Column0 Content名字 HorizontalAlignmentRight/TextBox Grid.Row0 Grid.Column1 Text{Binding Name} /Label Grid.Row1 Grid.Column0 Content性别 HorizontalAlignmentRight/TextBox Grid.Row1 Grid.Column1 Text{Binding Sex} /Label Grid.Row2 Grid.Column0 Content年龄 HorizontalAlignmentRight/TextBox Grid.Row2 Grid.Column1 Text{Binding Age} /Button Namebtn1 Grid.Row3 Grid.Column1 Width120 Height40 Margin5 Clickbtn1_Click显示对象信息/ButtonButton Namebtn2 Grid.Row4 Grid.Column1 Width120 Height40 Margin5 Clickbtn2_Click清除对象信息/Button/Grid/StackPanel /Window cs: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;namespace WPF_CH07_Demo01 {/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{Student student;public MainWindow(){InitializeComponent();//初始化数据student new Student() { Name 孙悟空, Sex 男, Age 18 };//指定数据上下文this.DataContext student;}/// summary/// 显示对象信息/// /summary/// param namesender/param/// param namee/paramprivate void btn1_Click(object sender, RoutedEventArgs e){MessageBox.Show(this.student.ToString());}/// summary/// 清空对象内容/// /summary/// param namesender/param/// param namee/paramprivate void btn2_Click(object sender, RoutedEventArgs e){this.student.Name null;this.student.Sex null;this.student.Age null;}}/// summary/// 页面视图 数据 模型/// /summarypublic class Student : INotifyPropertyChanged{private string name;public string Name{get { return name; }set{name value;OnPropertyChanged(Name);//引发事件}}private string sex;public string Sex{get { return sex; }set{sex value;OnPropertyChanged(Sex);//引发事件}}private int? age;public int? Age{get { return age; }set{age value;OnPropertyChanged(Age);//引发事件}}/// summary/// 属性改变事件/// /summarypublic event PropertyChangedEventHandler PropertyChanged;/// summary/// 事件处理函数/// /summary/// param nameproperty/parampublic void OnPropertyChanged(string property){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));}public override string ToString(){return string.Format(姓名{0},性别{1}年龄{2}, Name, Sex, Age);}} } 绑定ADO.NET 对象 xaml: Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledNamemainWindowTitleMainWindow Height450 Width800StackPanelTextBlock学生/TextBlockListBox ItemsSource{Binding StuListData}ListBox.ItemTemplateDataTemplateUniformGrid Columns3TextBlock Text{Binding Name} Margin5/TextBlock Text{Binding Sex} Margin5/TextBlock Text{Binding Age} Margin5//UniformGrid/DataTemplate/ListBox.ItemTemplate/ListBox/StackPanel /Window cs: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;namespace WPF_CH07_Demo01 {/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();//初始化数据this.InitialData();//指定数据上下文this.DataContext this;}/// summary/// 初始化数据/// /summarypublic void InitialData(){this.StuListData new DataTable();//列this.StuListData.Columns.Add(Name, typeof(string));this.StuListData.Columns.Add(Sex, typeof(string));this.StuListData.Columns.Add(Age, typeof(int));//行DataRow row1 this.StuListData.NewRow();row1[Name] 孙悟空;row1[Sex] 男;row1[Age] 18;DataRow row2 this.StuListData.NewRow();row2[Name] 猪八戒;row2[Sex] 男;row2[Age] 19;DataRow row3 this.StuListData.NewRow();row3[Name] 沙悟净;row3[Sex] 男;row3[Age] 20;//添加到数据表this.StuListData.Rows.Add(row1);this.StuListData.Rows.Add(row2);this.StuListData.Rows.Add(row3);}/// summary/// 学生数据表/// /summarypublic DataTable StuListData { get; set; }}} 绑定XML对象 xaml: Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledNamemainWindowTitleMainWindow Height450 Width800StackPanelListBox ItemsSource{Binding Source{StaticResource PeopleData}}ListBox.ItemTemplateDataTemplateUniformGrid Columns2TextBlock Width200 Text{Binding XPathName}/TextBlock Width200 Text{Binding XPathAge}//UniformGrid/DataTemplate/ListBox.ItemTemplate/ListBox/StackPanel /Window xml: ?xml version1.0 encodingutf-8 ? PeoplePerson Name孙悟空 Age30 /Person Name猪八戒 Age25 /Person Name沙悟净 Age35 / /PeopleApp.xaml: Application x:ClassWPF_CH07_Demo01.Appxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:localclr-namespace:WPF_CH07_Demo01StartupUriMainWindow.xamlApplication.ResourcesXmlDataProvider x:KeyPeopleData XPathPeople/Person Sourcedata.xml//Application.Resources /Application WPF的5种绑定模式 OneWay源变就更新目标属性TwoWay源变就更新目标并且目标变就更新源OneTime只根据源来设置目标以后都不会变OneWayToSource与OneWay相反Default可以单向或双向是靠被值定的源或目标是否有get或set来指定的 xaml: Window x:ClassWPF_CH07_Demo01.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WPF_CH07_Demo01mc:IgnorabledNameMainWindow1TitleMainWindow Height450 Width800StackPanelSlider Namesb1 Minimum0 Maximum100 Value50 Width300 Height 30 SmallChange1/GridGrid.RowDefinitionsRowDefinition/RowDefinition/RowDefinition/RowDefinition//Grid.RowDefinitionsGrid.ColumnDefinitionsColumnDefinition Width300/ColumnDefinition//Grid.ColumnDefinitionsLabel Grid.Row0 Grid.Column0 ContentOneWay/TextBox Grid.Row0 Grid.Column1 Text{Binding ElementNamesb1,PathValue,ModeOneWay}/Label Grid.Row1 Grid.Column0 ContentOneWayToSource/TextBox Grid.Row1 Grid.Column1 Text{Binding ElementNamesb1,PathValue,ModeOneWayToSource}/Label Grid.Row2 Grid.Column0 ContentTwoWay/TextBox Grid.Row2 Grid.Column1 Text{Binding ElementNamesb1,PathValue,ModeTwoWay}/Label Grid.Row3 Grid.Column0 ContentOneTime/TextBox Grid.Row3 Grid.Column1 Text{Binding ElementNamesb1,PathValue,ModeOneTime}//Grid/StackPanel /Window 课后作业 略
http://www.dnsts.com.cn/news/207251.html

相关文章:

  • 网站开发类比赛网站后台更新栏目后 网站
  • 大连建设银行招聘网站网络推广的方法有哪几种
  • 网站建设潍坊微博营销的技巧有哪些
  • 电子商务网站建设与推广企业网站建设的上市公司
  • 四川建设招投标网站任意的关键词或网站做引流
  • 韩国网站加速器wordpress 手机验证码插件
  • 高密 网站建设深圳低价网站建设
  • 深圳网站建设怎么做肥西上派网站开发
  • 网站建设的资金风险假山制作
  • 网站建设增长率国内最有趣的25个网站
  • 佛山市云时代网站建设公司北京建网站的公司哪个比较好
  • 政务公开做的好的网站有哪些wordpress 菜单的主题
  • 个人网站制作流程区块链开源平台
  • 信息网站建设福州网红餐厅
  • php企业网站开发方案如何运营网站
  • 要想浏览国外网站 应该怎么做在百度怎样建网站
  • 众筹网站建设夏都通app下载最新版本
  • 网站开发案例教程泊头市有做网站的吗
  • 课程网站建设ppt模板下载宝安中心医院是什么级别
  • 做外贸建网站无忧网站后台
  • idc网站源码下载沂南做网站
  • 珠海市律师网站建设怎么样wordpress本地安装500
  • wordpress 有趣的插件宁波seo推广服务
  • 乐清做网站公司哪家好东营企业自助建站
  • 临沂网站开发多少钱网站图片上传却不显示不出来
  • 网站设计建设维护巴中网站建设
  • 长沙网站建设专家西安搬家公司招聘
  • 一些设计网站wordpress页脚小工具
  • 投教网站建设中国建设银行网站软件
  • wordpress申请子站如何在自己的网站上做友情链接