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

兴义市住房和城乡建设局网签网站武昌手机网站

兴义市住房和城乡建设局网签网站,武昌手机网站,wordpress多说读者墙,做网站页面一般设置多大尺寸先看效果#xff1a; 上面的绑定值都是我们自定义的属性#xff0c;有了以上的提示#xff0c;那么我们可以轻松绑定字段#xff0c;再也不用担心错误了。附带源码。 目录 1.建立mvvm项目 2.cs后台使用DataContext绑定 3.xaml前台使用DataContext绑定 4.xaml前台使用Da…先看效果 上面的绑定值都是我们自定义的属性有了以上的提示那么我们可以轻松绑定字段再也不用担心错误了。附带源码。 目录 1.建立mvvm项目 2.cs后台使用DataContext绑定 3.xaml前台使用DataContext绑定 4.xaml前台使用DataContext单例模式绑定 1.建立mvvm项目 1.首先建立一个项目采用mvvm模式其中MainWindow.xaml相当于View层其余各层都比较简单。 2.BindingBase.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks;namespace WpfDataContextDemo.Common {public class BindingBase : INotifyPropertyChanged{public event PropertyChangedEventHandler PropertyChanged;//protected virtual void OnPropertyChanged(string propertyName)protected virtual void OnPropertyChanged([CallerMemberName] string propertyName )//此处使用特性{PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}} }3.StudentInfo.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WpfDataContextDemo.Common;namespace WpfDataContextDemo.Model {public class StudentInfo : BindingBase{private int id;public int Id{get { return id; }set { id value; OnPropertyChanged(); }}private string name;public string Name{get { return name; }set { name value; OnPropertyChanged(); }}private int age;public int Age{get { return age; }set { age value; OnPropertyChanged(); }}private bool b;public bool B{get { return b; }set { b value; OnPropertyChanged(); }}} }4.MainWindowViewModel.cs using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using WpfDataContextDemo.Model;namespace WpfDataContextDemo.ViewModel {public class MainWindowViewModel{public ObservableCollectionStudentInfo Infos { get; set; }public MainWindowViewModel(){Infos new ObservableCollectionStudentInfo(){new StudentInfo(){ Id1, Age11, NameTom,Bfalse},new StudentInfo(){ Id2, Age12, NameDarren,Bfalse},new StudentInfo(){ Id3, Age13, NameJacky,Bfalse},new StudentInfo(){ Id4, Age14, NameAndy,Bfalse}};}} }2.cs后台使用DataContext绑定 1.MainWindow.xaml.cs 只有一句话最重要 using System; using System.Collections.Generic; 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; using WpfDataContextDemo.ViewModel;namespace WpfDataContextDemo {/// summary/// Interaction logic for MainWindow.xaml/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();this.DataContext new MainWindowViewModel();}} }2.其中MainWindow.xaml Window x:ClassWpfDataContextDemo.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:WpfDataContextDemomc:IgnorabledTitleMainWindow Height450 Width800GridStackPanel Height295 HorizontalAlignmentLeft Margin10,10,0,0 NamestackPanel1 VerticalAlignmentTop Width427TextBlock Text{Binding Infos.Count } Margin5 /TextBlock Height23 NametextBlock1 Text学员编号: /TextBox Height23 NametxtStudentId Width301 HorizontalAlignmentLeft /TextBlock Height23 NametextBlock2 Text学员列表: /ListBox Height156 NamelbStudent Width305 HorizontalAlignmentLeft ItemsSource{Binding Infos}ListBox.ItemTemplateDataTemplateStackPanel NamestackPanel2 OrientationHorizontalTextBlock Text{Binding Id ,ModeTwoWay} Margin5 BackgroundRed/TextBlock x:Nameaa Text{Binding Name,ModeTwoWay, UpdateSourceTriggerExplicit} Margin5/TextBlock Text{Binding Age,ModeTwoWay} Margin5/TextBlock Text{Binding B,ModeTwoWay} Margin5//StackPanel/DataTemplate/ListBox.ItemTemplate/ListBox/StackPanel/Grid /Window此时我们输入Binding的时候不会显示IdName这些字段。 3.xaml前台使用DataContext绑定 1.先屏蔽后台cs的代码 2.前台MainWindow.xaml  Window x:ClassWpfDataContextDemo.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:WpfDataContextDemo xmlns:local1clr-namespace:WpfDataContextDemo.ViewModelmc:IgnorabledTitleMainWindow Height450 Width800Window.DataContextlocal1:MainWindowViewModel //Window.DataContextGridStackPanel Height295 HorizontalAlignmentLeft Margin10,10,0,0 NamestackPanel1 VerticalAlignmentTop Width427TextBlock Text{Binding Infos.Count } Margin5 /TextBlock Height23 NametextBlock1 Text学员编号: /TextBox Height23 NametxtStudentId Width301 HorizontalAlignmentLeft /TextBlock Height23 NametextBlock2 Text学员列表: /ListBox Height156 NamelbStudent Width305 HorizontalAlignmentLeft ItemsSource{Binding in}ListBox.ItemTemplateDataTemplateStackPanel NamestackPanel2 OrientationHorizontalTextBlock Text{Binding Id ,ModeTwoWay} Margin5 BackgroundRed/TextBlock x:Nameaa Text{Binding Name,ModeTwoWay, UpdateSourceTriggerExplicit} Margin5/TextBlock Text{Binding Age,ModeTwoWay} Margin5/TextBlock Text{Binding B,ModeTwoWay} Margin5//StackPanel/DataTemplate/ListBox.ItemTemplate/ListBox/StackPanel/Grid /Window3.最主要的是可以点击出来非常的清晰明了 4.xaml前台使用DataContext单例模式绑定 1.MainWindowViewModel.cs using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using WpfDataContextDemo.Model;namespace WpfDataContextDemo.ViewModel {public class MainWindowViewModel{//public ObservableCollectionStudentInfo Infos { get; set; }//public MainWindowViewModel()//{// Infos new ObservableCollectionStudentInfo()// {// new StudentInfo(){ Id1, Age11, NameTom,Bfalse},// new StudentInfo(){ Id2, Age12, NameDarren,Bfalse},// new StudentInfo(){ Id3, Age13, NameJacky,Bfalse},// new StudentInfo(){ Id4, Age14, NameAndy,Bfalse}// };//}private static readonly MainWindowViewModel instance new MainWindowViewModel();public static MainWindowViewModel Instance{get { return instance; }}public ObservableCollectionStudentInfo Infos { get; set; }public MainWindowViewModel(){Infos new ObservableCollectionStudentInfo(){new StudentInfo(){ Id1, Age11, NameTom,Bfalse},new StudentInfo(){ Id2, Age12, NameDarren,Bfalse},new StudentInfo(){ Id3, Age13, NameJacky,Bfalse},new StudentInfo(){ Id4, Age14, NameAndy,Bfalse}};}} }2.MainWindow.xaml Window x:ClassWpfDataContextDemo.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:WpfDataContextDemo xmlns:local1clr-namespace:WpfDataContextDemo.ViewModelmc:IgnorabledDataContext{x:Static local1:MainWindowViewModel.Instance}TitleMainWindow Height450 Width800!--Window.DataContextlocal1:MainWindowViewModel //Window.DataContext--GridStackPanel Height295 HorizontalAlignmentLeft Margin10,10,0,0 NamestackPanel1 VerticalAlignmentTop Width427TextBlock Text{Binding Infos.Count } Margin5 /TextBlock Height23 NametextBlock1 Text学员编号: /TextBox Height23 NametxtStudentId Width301 HorizontalAlignmentLeft /TextBlock Height23 NametextBlock2 Text学员列表: /ListBox Height156 NamelbStudent Width305 HorizontalAlignmentLeft ItemsSource{Binding Infos}ListBox.ItemTemplateDataTemplateStackPanel NamestackPanel2 OrientationHorizontalTextBlock Text{Binding Id ,ModeTwoWay} Margin5 BackgroundRed/TextBlock x:Nameaa Text{Binding Name ,ModeTwoWay, UpdateSourceTriggerExplicit} Margin5/TextBlock Text{Binding Age,ModeTwoWay} Margin5/TextBlock Text{Binding B,ModeTwoWay} Margin5//StackPanel/DataTemplate/ListBox.ItemTemplate/ListBox/StackPanel/Grid /Window源码https://download.csdn.net/download/u012563853/88407490 来源WPF中DataContext的绑定技巧_故里2130的博客-CSDN博客
http://www.w-s-a.com/news/908187/

相关文章:

  • 一个人在家做网站建设品牌策划流程
  • 小网站广告投放wordpress页面添加js
  • 仿制别人的竞价网站做竞价犯法吗wordpress添加版块
  • wordpress主题 站长互联网站备案表
  • 广州品牌策划公司排行南宁seo网络推广公司
  • 营销型网站图片肯德基网站开发
  • 网站的外链是什么wordpress开启菜单
  • 文字字体是什么网站西安博达网站建设
  • 北京南昌网站建设网站查看空间商
  • 网站建设人员职责分布乐清市网站建设设计
  • 网站建设etw网站建设陕西
  • 网站文章页内链结构不好可以改吗wordpress英文模板下载
  • 北京天通苑 做网站哈尔滨快速网站排名
  • 网站开发负责人是什么职位试剂网站建设
  • 什么是展示型网站wordpress链接视频
  • 佳木斯城乡建设局网站过年做哪个网站能致富
  • 石家庄快速网站搭建设计公司属于什么企业
  • 中小学智慧校园建设平台网站sem竞价推广
  • 想创建一个网站官方网站建设推广
  • 江门网站优化民间it网站建设
  • 科研实验室网站建设wordpress加载模板
  • 用r做简易的网站软件园二期做网站的公司
  • 菏泽网站建设价格长春高档网站建设
  • PHP网站开发与管理设计心得网站流量图怎么做
  • 苏州做网站企业wordpress点击文字弹出层
  • 做网站必要性中山古镇做网站
  • 增城住房和城乡建设局网站2021网站你懂我意思正能量
  • seo优秀网站深圳企业医疗网站建设
  • 单页 网站 模板重庆微信网站制作专家
  • 石家庄网站定制制作企业所得税优惠政策最新2022文件