资源简介
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 实现文件上传功能
- WPF Mircosoft.Ink墨迹手写输入(源码)
- Winform与WPF窗体互相调用方法
- WPFVisifire.Charts5.1.7.0 破解版
- WPF中DataGrid导出Excel和Word
- 在WPF中模拟SL的ChildWindow效果
- c# wpf全套教程视频教程
- 基于WPF开发的书籍管理软件
- WPF自定义控件-旋钮
- Wpf datagrid 增删改查
- WPF自定义搜索控件
- WPF自定义分页控件
- WPF中的DateTimePicker控件
- WPF漂亮导航面板源码20121022.zip
- WPF异形悬浮窗体源码
- 如何在WPF应用程序中通过HttpClient调用
- wpf rtmp,rtsp 播放器
- wpf 触屏虚拟键盘支持中英文切换
- Arcgis Runtime SDK for WPF文件过大,内附网
- DynamicDataDisplay.dll
- 小人快跑WPF帧动画效果
- C# wpf combobox带treeview的自定义控件
- WPF TabControl完美样式在下方显示+完美
- 串口通信 wpf C#
- wpf游戏2048
- 骑士周游问题WPF工程
- wpf led 时钟
- WPF流程图 开发
- WPF分页控件
评论
共有 条评论