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

免费图片素材网站有哪些招聘运营专员

免费图片素材网站有哪些,招聘运营专员,电商网站的分辨率,学校网站开发报价表先看效果: 上面的绑定值都是我们自定义的属性,有了以上的提示,那么我们可以轻松绑定字段,再也不用担心错误了。附带源码。 目录 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 ObservableCollection<StudentInfo> Infos { get; set; }public MainWindowViewModel(){Infos = new ObservableCollection<StudentInfo>(){new StudentInfo(){ Id=1, Age=11, Name="Tom",B=false},new StudentInfo(){ Id=2, Age=12, Name="Darren",B=false},new StudentInfo(){ Id=3, Age=13, Name="Jacky",B=false},new StudentInfo(){ Id=4, Age=14, Name="Andy",B=false}};}}
}

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/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();this.DataContext = new MainWindowViewModel();}}
}

2.其中MainWindow.xaml

<Window x:Class="WpfDataContextDemo.MainWindow"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:WpfDataContextDemo"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Grid><StackPanel Height="295" HorizontalAlignment="Left" Margin="10,10,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="427"><TextBlock  Text="{Binding Infos.Count  }" Margin="5" /><TextBlock Height="23" Name="textBlock1" Text="学员编号:" /><TextBox Height="23" Name="txtStudentId"  Width="301" HorizontalAlignment="Left"   /><TextBlock Height="23" Name="textBlock2" Text="学员列表:" /><ListBox Height="156" Name="lbStudent" Width="305" HorizontalAlignment="Left" ItemsSource="{Binding   Infos}"><ListBox.ItemTemplate><DataTemplate><StackPanel Name="stackPanel2" Orientation="Horizontal"><TextBlock  Text="{Binding Id  ,Mode=TwoWay}" Margin="5" Background="Red"/><TextBlock x:Name="aa" Text="{Binding Name,Mode=TwoWay, UpdateSourceTrigger=Explicit}" Margin="5"/><TextBlock  Text="{Binding  Age,Mode=TwoWay}" Margin="5"/><TextBlock  Text="{Binding B,Mode=TwoWay}" Margin="5"/></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox></StackPanel></Grid>
</Window>

此时,我们输入Binding的时候,不会显示Id,Name这些字段。

3.xaml前台使用DataContext绑定

1.先屏蔽后台cs的代码

2.前台MainWindow.xaml 

<Window x:Class="WpfDataContextDemo.MainWindow"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:WpfDataContextDemo" xmlns:local1="clr-namespace:WpfDataContextDemo.ViewModel"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Window.DataContext><local1:MainWindowViewModel /></Window.DataContext><Grid><StackPanel Height="295" HorizontalAlignment="Left" Margin="10,10,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="427"><TextBlock  Text="{Binding Infos.Count  }" Margin="5" /><TextBlock Height="23" Name="textBlock1" Text="学员编号:" /><TextBox Height="23" Name="txtStudentId"  Width="301" HorizontalAlignment="Left"   /><TextBlock Height="23" Name="textBlock2" Text="学员列表:" /><ListBox Height="156" Name="lbStudent" Width="305" HorizontalAlignment="Left" ItemsSource="{Binding  in}"><ListBox.ItemTemplate><DataTemplate><StackPanel Name="stackPanel2" Orientation="Horizontal"><TextBlock  Text="{Binding Id  ,Mode=TwoWay}" Margin="5" Background="Red"/><TextBlock x:Name="aa" Text="{Binding Name,Mode=TwoWay, UpdateSourceTrigger=Explicit}" Margin="5"/><TextBlock  Text="{Binding  Age,Mode=TwoWay}" Margin="5"/><TextBlock  Text="{Binding B,Mode=TwoWay}" Margin="5"/></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox></StackPanel></Grid>
</Window>

3.最主要的是,可以点击出来,非常的清晰明了

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 ObservableCollection<StudentInfo> Infos { get; set; }//public MainWindowViewModel()//{//    Infos = new ObservableCollection<StudentInfo>()//    {//        new StudentInfo(){ Id=1, Age=11, Name="Tom",B=false},//        new StudentInfo(){ Id=2, Age=12, Name="Darren",B=false},//        new StudentInfo(){ Id=3, Age=13, Name="Jacky",B=false},//        new StudentInfo(){ Id=4, Age=14, Name="Andy",B=false}//    };//}private static readonly MainWindowViewModel instance = new MainWindowViewModel();public static MainWindowViewModel Instance{get { return instance; }}public ObservableCollection<StudentInfo> Infos { get; set; }public MainWindowViewModel(){Infos = new ObservableCollection<StudentInfo>(){new StudentInfo(){ Id=1, Age=11, Name="Tom",B=false},new StudentInfo(){ Id=2, Age=12, Name="Darren",B=false},new StudentInfo(){ Id=3, Age=13, Name="Jacky",B=false},new StudentInfo(){ Id=4, Age=14, Name="Andy",B=false}};}}
}

2.MainWindow.xaml

<Window x:Class="WpfDataContextDemo.MainWindow"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:WpfDataContextDemo" xmlns:local1="clr-namespace:WpfDataContextDemo.ViewModel"mc:Ignorable="d"DataContext="{x:Static local1:MainWindowViewModel.Instance}"Title="MainWindow" Height="450" Width="800"><!--<Window.DataContext><local1:MainWindowViewModel /></Window.DataContext>--><Grid><StackPanel Height="295" HorizontalAlignment="Left" Margin="10,10,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="427"><TextBlock  Text="{Binding Infos.Count  }" Margin="5" /><TextBlock Height="23" Name="textBlock1" Text="学员编号:" /><TextBox Height="23" Name="txtStudentId"  Width="301" HorizontalAlignment="Left"   /><TextBlock Height="23" Name="textBlock2" Text="学员列表:" /><ListBox Height="156" Name="lbStudent" Width="305" HorizontalAlignment="Left" ItemsSource="{Binding  Infos}"><ListBox.ItemTemplate><DataTemplate><StackPanel Name="stackPanel2" Orientation="Horizontal"><TextBlock  Text="{Binding Id  ,Mode=TwoWay}" Margin="5" Background="Red"/><TextBlock x:Name="aa" Text="{Binding Name ,Mode=TwoWay, UpdateSourceTrigger=Explicit}" Margin="5"/><TextBlock  Text="{Binding  Age,Mode=TwoWay}" Margin="5"/><TextBlock  Text="{Binding B,Mode=TwoWay}" Margin="5"/></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox></StackPanel></Grid>
</Window>

 源码:https://download.csdn.net/download/u012563853/88407490

来源:WPF中DataContext的绑定技巧_故里2130的博客-CSDN博客

http://www.yayakq.cn/news/76368/

相关文章:

  • 福建网站建设价格几分钟做网站
  • 外网网站有什么好的推荐哪个网站可以悬赏做图
  • 东莞网站建设五金建材电子商务网站建设期末试卷答案
  • 佛山市城乡住房建设局网站重庆企业网站开发
  • 域名商的网站建设网银登录网站
  • 专题定制网站建设html5的静态壁纸
  • 电子商务网站建设规划的内容wordpress 插件新页面
  • 单位网站建设收费标准网络营销包括的主要内容有
  • 青岛网站建设加王道下拉怎么把网站做成手机版的
  • 建设网站的成本有哪些前端学习网站建设教程
  • 网站建设怎么分析市场分析网站被k 但收录内页
  • 网站优化改动怎么做苏州建网站公司
  • 如何在国外网站做免费推广微信小程序功能开发
  • 衡阳建设学校网站网站的基础知识
  • 网站建设与管理试题及答案黑料社2023
  • ui下载高清素材的网站有哪些wordpress搬家换域名
  • 网站评论列表模板域名解析错误无法上网
  • 北京网站优化外包公司佛山制作做网站
  • 漂亮的html5网页北京中文seo
  • 建设网站需要那几部wordpress 两栏 主题
  • 网站域名怎么查做ppt网站动态
  • 重庆承越网站制作公司qq邮箱网页版登录入口
  • 怎样设计手机网站建设网站编程学习
  • 大连网站建设佳熙科技公司商务网站建设学期总结
  • 都江堰网站建设青木三色品牌商城网站开发
  • 公司的网站建设费用属于什么费小程序制作流程微信
  • 做外贸自己的公司网站中山精品网站建设新闻
  • 用爱站工具包如何做网站地图网页设计与制作教程素材
  • 关于服装店网站建设的策划方案wordpress退款插件
  • 金泉网 网站建设做网站需要要多少钱