资源简介
WPF自定义控件,动态添加、删除行,支持编辑,对外提供DataTable数据

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Data;
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;
namespace UnityApp.Unity
{
///
/// TableControl.xaml 的交互逻辑
///
public partial class TableControl : UserControl
{
private DataTable _dt = new DataTable();
public TableControl()
{
InitializeComponent();
_dt.Columns.Add(new DataColumn(“ParamKey“ typeof(string)));
_dt.Columns.Add(new DataColumn(“ParamValue“ typeof(string)));
this.dgData.ItemsSource = null;
this.dgData.ItemsSource = _dt.DefaultView;
}
#region 自定义依赖项属性
///
/// 数据源
///
public DataTable DataSource
{
get { return ((DataView)this.dgData.ItemsSource).Table; }
set { SetValue(DataSourceProperty value); }
}
public static readonly DependencyProperty DataSourceProperty =
DependencyProperty.Register(“DataSource“ typeof(DataTable) typeof(TableControl) new Propertymetadata(new DataTable() DataSourceChanged));
private static void DataSourceChanged(Dependencyobject d DependencyPropertyChangedEventArgs e)
{
TableControl control = d as TableControl;
if (e.NewValue != e.OldValue)
{
DataTable dt = e.NewValue as DataTable;
control._dt = dt;
control.dgData.ItemsSource = null;
control.dgData.ItemsSource = control._dt.DefaultView;
}
}
///
/// 是否编辑状态
///
public bool IsEdit
{
get { return (bool)GetValue(IsEditProperty); }
set { SetValue(IsEditProperty value); }
}
// Using a DependencyProperty as the backing store for IsEdit. This enables animation styling binding etc...
public static readonly DependencyProperty IsEditProperty =
DependencyProperty.Register(“IsEdit“ typeof(bool) typeof(TableControl) new Propertymetadata(true IsEditChanged));
private static void IsEditChanged(Dependencyobject d DependencyPropertyChangedEventArgs e)
{
TableControl control = d as TableControl;
bool isEdit = Convert.ToBoolean(e.NewValue);
if (!isEdit)
{
int len = control.dgData.Columns.Count;
control.dgData.Columns[len - 1].Visibility = Visibility.Collapsed;
control.dgData.IsReadOnly = true;
control.btnA
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6680 2017-06-10 17:02 TableControl.xaml
文件 3965 2017-06-10 16:42 TableControl.xaml.cs
----------- --------- ---------- ----- ----
10645 2
- 上一篇:CSS样式 (仿招聘网站)
- 下一篇:WPF资源字典中的控件事件触发
相关资源
- 用WPF开发的多人聊天室 语言C#
- WPF控件库HandyControl
- WPF
- c# wpf实现的上位机
- VisionPro控件在WPF 应用
- WPF使用MVVM
- winform实现饼状图、柱状图、折线图(
- C#中WPF联合Halcon的一个学习(解决内存
- WPF CEFSHARP 支持 MP4
- WPF贝塞尔曲线
- WPF 简单控件集
- WPF鼠标拖动控件源码
- wpf开发教程
- AduMusic迷你音乐盒WPF源码
- WPF PDF封装(放大、缩小、单页、双页
- C# .NET5.0(net core)基于WPF(XAML)开发
- WPF MVVM 基础入门
- wpf echart
- windorm 加载WPF控件 ,实现dxf文件显示
- WPF Control Development
- wpf Dock window
- WPF 隐蔽查看股票行情工具
- WPF控件库(HandyControl)
- 别踩白块wpf 源码
- WPF贪吃蛇
- WPF Task 多任务
- WPF path动画
- WPF 最基础的组件拖动、改变大小
- WPF DATAGRID 数据绑定
- WPF绘制坐标系(可放大缩小)
评论
共有 条评论