Difference between revisions of "Windows Presentation Foundation"
From Richard's Wiki
Line 1: | Line 1: | ||
+ | * Set max characters in column for WPF DataGridColumn. Use DataGridTextColumn.EditingElementStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, maxColumnLength)): | ||
+ | |||
+ | private void DataGrid_AutoGeneratedColumns(object sender, EventArgs e) | ||
+ | { | ||
+ | DataGrid datagrid = sender as DataGrid; | ||
+ | if (datagrid == null) return; | ||
+ | var columns = datagrid.Columns; | ||
+ | var orderedColumns = columns | ||
+ | .OrderBy(c => GetDisplayInfo(ViewModel.CurrentType, c.Header as string).DisplayOrder) | ||
+ | .ToList(); | ||
+ | foreach (DataGridColumn dataGridColumn in columns) | ||
+ | { | ||
+ | dataGridColumn.DisplayIndex = orderedColumns.IndexOf(dataGridColumn); | ||
+ | DisplayInfo displayInfo = GetDisplayInfo(ViewModel.CurrentType, dataGridColumn.Header as string); | ||
+ | dataGridColumn.Header = displayInfo.DisplayName; | ||
+ | if ((dataGridColumn is DataGridTextColumn) && | ||
+ | (displayInfo.MaxLength.HasValue)) | ||
+ | { | ||
+ | int maxColumnLength = displayInfo.MaxLength.Value; | ||
+ | ((DataGridTextColumn)dataGridColumn).EditingElementStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, maxColumnLength)); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
* [http://windowsclient.net/blogs/tanuagrawal/archive/2010/02/23/Debugging-XAML-Bindings-in-WPF-by-Tanu-Agrawal.aspx Debugging XAML Bindings in WPF] | * [http://windowsclient.net/blogs/tanuagrawal/archive/2010/02/23/Debugging-XAML-Bindings-in-WPF-by-Tanu-Agrawal.aspx Debugging XAML Bindings in WPF] | ||
* [http://msdn.microsoft.com/en-us/magazine/dd419663.aspx WPF Apps With The Model-View-ViewModel Design Pattern (MSDN Magazine)] | * [http://msdn.microsoft.com/en-us/magazine/dd419663.aspx WPF Apps With The Model-View-ViewModel Design Pattern (MSDN Magazine)] |
Revision as of 23:48, 15 November 2011
- Set max characters in column for WPF DataGridColumn. Use DataGridTextColumn.EditingElementStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, maxColumnLength)):
private void DataGrid_AutoGeneratedColumns(object sender, EventArgs e) { DataGrid datagrid = sender as DataGrid; if (datagrid == null) return; var columns = datagrid.Columns; var orderedColumns = columns .OrderBy(c => GetDisplayInfo(ViewModel.CurrentType, c.Header as string).DisplayOrder) .ToList(); foreach (DataGridColumn dataGridColumn in columns) { dataGridColumn.DisplayIndex = orderedColumns.IndexOf(dataGridColumn); DisplayInfo displayInfo = GetDisplayInfo(ViewModel.CurrentType, dataGridColumn.Header as string); dataGridColumn.Header = displayInfo.DisplayName; if ((dataGridColumn is DataGridTextColumn) && (displayInfo.MaxLength.HasValue)) { int maxColumnLength = displayInfo.MaxLength.Value; ((DataGridTextColumn)dataGridColumn).EditingElementStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, maxColumnLength)); } } }
- Debugging XAML Bindings in WPF
- WPF Apps With The Model-View-ViewModel Design Pattern (MSDN Magazine)
- A Guided Tour of WPF - A simple introduction to WPF
- WPF Tutorial - Using WPF In WinForms
- WPF: Validation made easy with IDataErrorInfo
- Customize Data Display with Data Binding and WPF (How to display errors, handle IDataErrorInfo)
- Silverlight and XAML Namespace Declarations
- media:WpfCustomBindingClass.zip Example Custom WPF Binding Class VS2008 Project