DataTemple-创建数据模板
来源:互联网 发布:淘宝店铺流失商品 编辑:程序博客网 时间:2024/06/11 00:09
using System;
using System.Collections.Generic;
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;
using System.Data;
using System.Dynamic;
using System.Windows.Interop;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 1; i < 10; i++)
{
Label labLine = new Label();
labLine.Content = "message" + i.ToString();
Button btn = new Button();
btn.Content = "测试按钮" + i.ToString();
btn.Click += new RoutedEventHandler(btn_click);
wpQueyFan.Children.Add(labLine);
wpQueyFan.Children.Add(btn);
}
QueryModel();
QueryModelNew();
GetDataGrid();
}
private void btn_click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
MessageBox.Show(btn.Content.ToString());
}
private void QueryModel()
{
// Create a DataTable.
DataTable table = new DataTable("Product");
// Create a DataColumn and set various properties.
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Price";
column.DefaultValue = 25;
DataColumn columnName = new DataColumn();
columnName.DataType = System.Type.GetType("System.String");
columnName.AllowDBNull = false;
columnName.Caption = "Name";
columnName.ColumnName = "Name";
columnName.DefaultValue = "NA";
// Add the column to the table.
table.Columns.Add(column);
table.Columns.Add(columnName);
// Add 10 rows and set values.
DataRow row;
for (int i = 0; i < 1000; i++)
{
row = table.NewRow();
row["Price"] = i + 1;
row["Name"] = "名称为:" + i.ToString();
// Be sure to add the new row to the
// DataRowCollection.
table.Rows.Add(row);
}
dgModel.ItemsSource = table.DefaultView;
dgModel2.ItemsSource = table.DefaultView;
}
private void QueryModelNew()
{
// Create a DataTable.
DataTable table = new DataTable("Product");
DataRow dr;
// Create a DataColumn and set various properties.
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Price";
column.DefaultValue = 25;
DataColumn columnName = new DataColumn();
columnName.DataType = System.Type.GetType("System.String");
columnName.AllowDBNull = false;
columnName.Caption = "Name";
columnName.ColumnName = "Name";
columnName.DefaultValue = "NA";
// Add the column to the table.
table.Columns.Add(column);
table.Columns.Add(columnName);
// Add 10 rows and set values.
DataRow row;
for (int i = 0; i < 1000; i++)
{
row = table.NewRow();
row["Price"] = i + 1;
row["Name"] = "名称为:" + i.ToString();
// Be sure to add the new row to the
// DataRowCollection.
table.Rows.Add(row);
}
for (int j = 0; j < table.Rows.Count; j++)
{
if (j % 6 == 0)
{
}
}
}
private void GetDataGrid()
{
DataGridTextColumn dc = new DataGridTextColumn();
dc.IsReadOnly = true;
dc.Header = "标题";
dc.Width = 60;
dgModel2.Columns.Add(dc);
DataGridTemplateColumn dgtc = new DataGridTemplateColumn();
DataTemplate dt = new DataTemplate();
FrameworkElementFactory fef = new FrameworkElementFactory(typeof (CheckBox));
Binding binding = new Binding();
binding.Path = new PropertyPath("MarketIndicator");
fef.SetBinding(CheckBox.ContentProperty, binding);
fef.SetValue(CheckBox.ForegroundProperty, Brushes.White);
dt.VisualTree = fef;
dgtc.CellTemplate = dt;
DataGridTemplateColumn dgtc1 = new DataGridTemplateColumn();
DataTemplate dt1= new DataTemplate();
FrameworkElementFactory fef1 = new FrameworkElementFactory(typeof(TextBox));
Binding binding1 = new Binding();
binding1.Path = new PropertyPath("MarketIndicator");
// fef1.SetBinding(TextBox.ContentProperty, binding);
fef1.SetValue(TextBox.ForegroundProperty, Brushes.Blue);
dt1.VisualTree = fef1;
dgtc1.CellTemplate = dt1;
dgModel2.Columns.Add(dgtc1);
}
}
}
using System.Collections.Generic;
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;
using System.Data;
using System.Dynamic;
using System.Windows.Interop;
namespace WpfApplication3
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 1; i < 10; i++)
{
Label labLine = new Label();
labLine.Content = "message" + i.ToString();
Button btn = new Button();
btn.Content = "测试按钮" + i.ToString();
btn.Click += new RoutedEventHandler(btn_click);
wpQueyFan.Children.Add(labLine);
wpQueyFan.Children.Add(btn);
}
QueryModel();
QueryModelNew();
GetDataGrid();
}
private void btn_click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
MessageBox.Show(btn.Content.ToString());
}
private void QueryModel()
{
// Create a DataTable.
DataTable table = new DataTable("Product");
// Create a DataColumn and set various properties.
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Price";
column.DefaultValue = 25;
DataColumn columnName = new DataColumn();
columnName.DataType = System.Type.GetType("System.String");
columnName.AllowDBNull = false;
columnName.Caption = "Name";
columnName.ColumnName = "Name";
columnName.DefaultValue = "NA";
// Add the column to the table.
table.Columns.Add(column);
table.Columns.Add(columnName);
// Add 10 rows and set values.
DataRow row;
for (int i = 0; i < 1000; i++)
{
row = table.NewRow();
row["Price"] = i + 1;
row["Name"] = "名称为:" + i.ToString();
// Be sure to add the new row to the
// DataRowCollection.
table.Rows.Add(row);
}
dgModel.ItemsSource = table.DefaultView;
dgModel2.ItemsSource = table.DefaultView;
}
private void QueryModelNew()
{
// Create a DataTable.
DataTable table = new DataTable("Product");
DataRow dr;
// Create a DataColumn and set various properties.
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Price";
column.DefaultValue = 25;
DataColumn columnName = new DataColumn();
columnName.DataType = System.Type.GetType("System.String");
columnName.AllowDBNull = false;
columnName.Caption = "Name";
columnName.ColumnName = "Name";
columnName.DefaultValue = "NA";
// Add the column to the table.
table.Columns.Add(column);
table.Columns.Add(columnName);
// Add 10 rows and set values.
DataRow row;
for (int i = 0; i < 1000; i++)
{
row = table.NewRow();
row["Price"] = i + 1;
row["Name"] = "名称为:" + i.ToString();
// Be sure to add the new row to the
// DataRowCollection.
table.Rows.Add(row);
}
for (int j = 0; j < table.Rows.Count; j++)
{
if (j % 6 == 0)
{
}
}
}
private void GetDataGrid()
{
DataGridTextColumn dc = new DataGridTextColumn();
dc.IsReadOnly = true;
dc.Header = "标题";
dc.Width = 60;
dgModel2.Columns.Add(dc);
DataGridTemplateColumn dgtc = new DataGridTemplateColumn();
DataTemplate dt = new DataTemplate();
FrameworkElementFactory fef = new FrameworkElementFactory(typeof (CheckBox));
Binding binding = new Binding();
binding.Path = new PropertyPath("MarketIndicator");
fef.SetBinding(CheckBox.ContentProperty, binding);
fef.SetValue(CheckBox.ForegroundProperty, Brushes.White);
dt.VisualTree = fef;
dgtc.CellTemplate = dt;
DataGridTemplateColumn dgtc1 = new DataGridTemplateColumn();
DataTemplate dt1= new DataTemplate();
FrameworkElementFactory fef1 = new FrameworkElementFactory(typeof(TextBox));
Binding binding1 = new Binding();
binding1.Path = new PropertyPath("MarketIndicator");
// fef1.SetBinding(TextBox.ContentProperty, binding);
fef1.SetValue(TextBox.ForegroundProperty, Brushes.Blue);
dt1.VisualTree = fef1;
dgtc1.CellTemplate = dt1;
dgModel2.Columns.Add(dgtc1);
}
}
}
0 0
- DataTemple-创建数据模板
- ArcMap如何创建数据编辑模板,高效完成数据采集
- 利用数据绑定和模板创建Atlas应用程序
- 创建模板
- 如何使用动态创建模板列并绑定数据(GridView,Repeater,DataGrid)
- 如何使用动态创建模板列并绑定数据(GridView,Repeater,DataGrid)
- 如何使用动态创建模板列并绑定数据(GridView,Repeater,DataGrid)
- 动态创建模板列并绑定数据(GridView,Repeater,DataGrid)
- AJAX获取数据,EJS创建HTML模板的简单项目使用
- 创建页模板
- 创建自定义模板BuildingCustomTemplates
- 创建SharePoint站点模板
- 创建Ajax Toolkit模板
- procedure 创建模板
- 创建Xcode 模板
- 创建文档模板
- 创建WordPress页面模板
- 创建Xcode自定义模板
- eclipse 连接 cdh5.5 插件
- 动态加载Dll时,通过Type生成类对象
- 递归实现字符串反向输入
- js中报错:$ is not defined
- 谁将会参加比赛的问题(java 实现)
- DataTemple-创建数据模板
- Nginx反向代理和负载均衡部署指南
- 移动端H5各种各样的列表的制作方法(三) by FungLeo
- java 内存调优
- hadoop关于block总结
- 网络编程学习笔记--socket可读可写条件
- Windows 两条命令找到占用你某个端口的程序
- 关于a标签的onclick与href的执行顺序
- java并发编程基础之对象的共享