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绑定数据源的更多相关文章

  1. WPF绑定数据源之RelativeSource

    Command="{Binding ConfirmRegisterCommand}" CommandParameter="{Binding RelativeSource= ...

  2. WPF 绑定以基础数据类型为集合的无字段名的数据源

    WPF 绑定以基础数据类型为集合的无字段名的数据源 运行环境:Window7 64bit,.NetFramework4.61,C# 6.0: 编者:乌龙哈里 2017-02-21 我们在控件的数据绑定 ...

  3. WPF利用通过父控件属性来获得绑定数据源RelativeSource

    WPF利用通过父控件属性来获得绑定数据源RelativeSource   有时候我们不确定作为数据源的对象叫什么名字,但知道作为绑定源与UI布局有相对的关系,如下是一段XAML代码,说明多层布局控件中 ...

  4. WPF绑定各种数据源之object数据源

    一.WPF绑定各种数据源索引 WPF 绑定各种数据源之Datatable WPF绑定各种数据源之object数据源 WPF绑定各种数据源之xml数据源 WPF绑定各种数据源之元素控件属性 Bindin ...

  5. WPF学习笔记——ListBox用ItemsSource绑定数据源

    作为一个WPF初学者,感到困难重重.在网上想查个ListBox绑定数据源的示例,结果出来一大堆代码,一看心就烦. 我给个简洁一点的代码: 后台代码: protected class UserItem ...

  6. WPF绑定各种数据源之xml数据源

    一.WPF绑定各种数据源索引 WPF 绑定各种数据源之Datatable WPF绑定各种数据源之object数据源 WPF绑定各种数据源之xml数据源 WPF绑定各种数据源之元素控件属性 Bindin ...

  7. WPF DevExpress Chart控件 界面绑定数据源,不通过C#代码进行绑定

    <Grid x:Name="myGrid" Loaded="Grid_Loaded" DataContext="{Binding PartOne ...

  8. WPF快速入门系列(4)——深入解析WPF绑定

    一.引言 WPF绑定使得原本需要多行代码实现的功能,现在只需要简单的XAML代码就可以完成之前多行后台代码实现的功能.WPF绑定可以理解为一种关系,该关系告诉WPF从一个源对象提取一些信息,并将这些信 ...

  9. WPF绑定的ListBox获取ListBoxItem及GoToState应用

    现公司项目中需要制作一个扇形菜单,菜单项是用ListBox重写Style实现的,其数据是绑定的.菜单的每一项都有Normal,MouseOver和Selected三种状态,这三种状态当然可以通过鼠标移 ...

随机推荐

  1. Python的平凡之路(8)

    (本文是对平凡之路(7)的补充等) 一.动态导入模块 import importlib __import__('import_lib.metaclass') #这是解释器自己内部用的 #importl ...

  2. Active Record: 資料庫遷移(Migration) (转)

    Active Record: 資料庫遷移(Migration) Programming today is a race between software engineers striving to b ...

  3. 隐藏ArcGIS server设置的用户名

    打开注册表编辑器,定位到“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\ SpecialAccoun ...

  4. C#中的IntPtr类型

    本文转自:http://zhidao.baidu.com/question/22825956.html 问: c#中无法将类型“int”隐式转换为“System.IntPtr” 这个是我引用了一个ap ...

  5. plsql developer 导出导入存储过程和函数

    说明:需要把建表脚本及表数据分开导出,操作很简单.一.导出表及存储过程等对象:1. 登录PL-SQL Developer2. 选择只显示本用户的对象,如下图:3. 选择菜单“Tools——〉Expor ...

  6. HDU 2089 不要62

    也是简单的数位dp. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...

  7. 前端开发环境搭建 Grunt Bower、Requirejs 、 Angular

    现在web开发的趋势是前后端分离.前端采用某些js框架,后端采用某些语言提供restful API,两者以json格式进行数据交互. 如果后端采用node.js,则前后端可以使用同一种语言,共享某些可 ...

  8. REDIS key notification

    Commands Clients Documentation Community Download Support License Join us in London October 19th for ...

  9. 一种Go使用tcp检测超时的方式

    c.SetReadDeadline(time.Now()) if _, err := c.Read(one); err == io.EOF { l.Printf(logger.LevelDebug, ...

  10. SVG文档的注意事项

    SVG 是 HTML5 关于描述矢量图的元素.可以写在 <html> </html> 中,也可以保存为一个单独的.svg文件. 单独作为一个svg文件的时候,有一点规则需要注意 ...