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

网站定制开发收费标准是多少河源市住宅和城乡规划建设局网站

网站定制开发收费标准是多少,河源市住宅和城乡规划建设局网站,wordpress 安装环境,宁夏建设厅网站旧版先看效果: 上面的绑定值都是我们自定义的属性,有了以上的提示,那么我们可以轻松绑定字段,再也不用担心错误了。附带源码。 目录 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/849515/

相关文章:

  • 青海建设厅报名网站网站首页幻灯片代码
  • 成都网站建设招标百度新闻搜索
  • 长沙大的建网站公司凡科小程序模板
  • 深圳微信网站公司哪家好优书网有官方app吗
  • 汕头企业网站推广技巧网站的大图标怎么做的
  • 邯郸wap网站建设报价百度信息流网站可以做落地页吗
  • 有没有专门做中式的设计网站怎样利用网站做引流
  • 免费网站建设推荐阿勒泰建设招聘网站
  • 专业的网站建设收费标准茂名网站制作价格
  • 做设计有哪些好用的素材网站有哪些uniapp商城源码
  • 网站建设与运营总结wordpress 首页模版
  • 营销网站怎么做合适湖南省建设厅电话号码是多少
  • 利用帝国软件如何做网站对文化传播网站建设的建议
  • 德国设计网站大全部队网站怎么做
  • 模板建站有什么优势网页制作基础教程图片
  • 求一个能用的网站合肥市建设投资有限公司
  • 网站制作公司有哪些证360软件商店
  • 哈尔滨网站设计报价做网站至少要花多少钱
  • 为什么做金融网站犯法织梦建站教程
  • 网站建设实验总结报告学做衣服网站有哪些
  • 网站诊断方案wordpress插件排行
  • 做网站维护挣钱吗成都最好的seo外包
  • 如何用源代码做网站全屋定制设计软件
  • 做基金哪个网站好收录快网站
  • 壶关网站建设网站首页引导页模版
  • 建网站需要服务器吗上海建设工程造价信息网官网
  • c 小说网站开发教程晋江论坛网友留言区
  • 德阳建设厅官方网站外贸人才网哪家最好
  • 门户网站团队建设最好看的免费网站源码
  • 安康哪里做网站自己制作logo免费 生成器