WPF绑定数据源
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
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 WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public ObservableCollection<TestDataItem> list = new ObservableCollection<TestDataItem>();
public MainWindow()
{
InitializeComponent();
for (int i = 0; i < 20; i++)
{
list.Add(new TestDataItem() { Id = Guid.NewGuid()});
}
this.DataContext = list;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
ObservableCollection<TestDataItem> temp = this.DataContext as ObservableCollection<TestDataItem>;
if (temp != null && temp.Count > 0)
{
temp.Add(new TestDataItem() { Id = Guid.NewGuid() });
}
}
}
public class TestDataItem:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private Guid id = Guid.NewGuid();
public Guid Id
{
get { return Guid.NewGuid(); }
set
{
this.id = value;
if (this.PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Id"));
}
}
}
}
}
______________________________________
<Window xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel Orientation="Vertical">
<Button Click="Button_Click_1" Width="30" Height="30" Content="OK"/>
<dxg:GridControl x:Name="grid" Height="500" ItemsSource="{Binding}">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Id" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" />
</dxg:GridControl.View>
</dxg:GridControl>
</StackPanel>
</Grid>
</Window>
WPF绑定数据源的更多相关文章
- WPF绑定数据源之RelativeSource
Command="{Binding ConfirmRegisterCommand}" CommandParameter="{Binding RelativeSource= ...
- WPF 绑定以基础数据类型为集合的无字段名的数据源
WPF 绑定以基础数据类型为集合的无字段名的数据源 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-21 我们在控件的数据绑定 ...
- WPF利用通过父控件属性来获得绑定数据源RelativeSource
WPF利用通过父控件属性来获得绑定数据源RelativeSource 有时候我们不确定作为数据源的对象叫什么名字,但知道作为绑定源与UI布局有相对的关系,如下是一段XAML代码,说明多层布局控件中 ...
- WPF绑定各种数据源之object数据源
一.WPF绑定各种数据源索引 WPF 绑定各种数据源之Datatable WPF绑定各种数据源之object数据源 WPF绑定各种数据源之xml数据源 WPF绑定各种数据源之元素控件属性 Bindin ...
- WPF学习笔记——ListBox用ItemsSource绑定数据源
作为一个WPF初学者,感到困难重重.在网上想查个ListBox绑定数据源的示例,结果出来一大堆代码,一看心就烦. 我给个简洁一点的代码: 后台代码: protected class UserItem ...
- WPF绑定各种数据源之xml数据源
一.WPF绑定各种数据源索引 WPF 绑定各种数据源之Datatable WPF绑定各种数据源之object数据源 WPF绑定各种数据源之xml数据源 WPF绑定各种数据源之元素控件属性 Bindin ...
- WPF DevExpress Chart控件 界面绑定数据源,不通过C#代码进行绑定
<Grid x:Name="myGrid" Loaded="Grid_Loaded" DataContext="{Binding PartOne ...
- WPF快速入门系列(4)——深入解析WPF绑定
一.引言 WPF绑定使得原本需要多行代码实现的功能,现在只需要简单的XAML代码就可以完成之前多行后台代码实现的功能.WPF绑定可以理解为一种关系,该关系告诉WPF从一个源对象提取一些信息,并将这些信 ...
- WPF绑定的ListBox获取ListBoxItem及GoToState应用
现公司项目中需要制作一个扇形菜单,菜单项是用ListBox重写Style实现的,其数据是绑定的.菜单的每一项都有Normal,MouseOver和Selected三种状态,这三种状态当然可以通过鼠标移 ...
随机推荐
- Linux准确获取IP
有时搞一些跨网段的工程和应用,需要尽量准确的知道电信.网通.铁通等电信运营商的IP地址段分配情况,可网上的资料不但很少,而且经常都是N个月前的过期资料…… APNIC是管理亚太地区IP地址分配的机构, ...
- POJ 3041 Asteroids 匈牙利算法,最大流解法,行列为点 难度:1
http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector& ...
- Topcoder SRM 583 DIV2 SwappingDigits
题目题意是交换一次,使数字最小,且数字前面不能有前导0 string minNumber(string num) { string res = num; for(int i = 0 ; i < ...
- Enable SSHD on Ubuntu
https://help.ubuntu.com/community/SSH/OpenSSH/Configuring
- 两个小的java程序,用于练习java基本语法
1.输入两个数,求其加减乘除.用窗口的形式呈现 import javax.swing.JOptionPane; public class JJCC { public static void main( ...
- Simple Maven Project
为pom.xml添加组织,法律和开发人员信息 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...
- Linux上vi(vim)编辑器使用教程
vi(vim)是上Linux非常常用的编辑器,很多Linux发行版都默认安装了vi(vim).vi(vim)命令繁多但是如果使用灵活之后将会大大提高效率.vi是“visual interface”的缩 ...
- CentOS6.5安装openLdap
一.关闭防火墙和selinux 关闭防火墙 chkconfig iptables off service iptables stop 关闭selinux vim /etc/selinux/config ...
- JS URL参数传递 谷歌乱码解决
//第一个页面 var name=encodeURIComponent("参数"); var url="test1.html?name="+name; //第二 ...
- C语言解决八皇后问题
#include <stdio.h> #include <stdlib.h> /* this code is used to cope with the problem of ...