Difference between revisions of "Windows Presentation Foundation"

From Richard's Wiki
Jump to: navigation, search
 
Line 1: Line 1:
 +
* [[Confirm/Information Dialog with Caliburn Micro]]
 
* Set max characters in column for WPF DataGridColumn. Use DataGridTextColumn.EditingElementStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, maxColumnLength)) (see [http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6d56e577-5ccf-45f4-af37-e914a9e7edad/ http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6d56e577-5ccf-45f4-af37-e914a9e7edad/]:
 
* Set max characters in column for WPF DataGridColumn. Use DataGridTextColumn.EditingElementStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, maxColumnLength)) (see [http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6d56e577-5ccf-45f4-af37-e914a9e7edad/ http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6d56e577-5ccf-45f4-af37-e914a9e7edad/]:
  

Latest revision as of 17:29, 8 October 2013

private void DataGrid_AutoGeneratedColumns(object sender, EventArgs e)
       {
           DataGrid datagrid = sender as DataGrid;
           if (datagrid == null) return;
           Type entityMetadataType = MetadataType(ViewModel.CurrentType);
           var columns = datagrid.Columns;
           var orderedColumns = columns
               .OrderBy(c => DisplayMetadataHelper.GetDisplayInfo(entityMetadataType, c.Header as string).DisplayOrder)
               .ToList();
           foreach (DataGridColumn dataGridColumn in columns)
           {
               dataGridColumn.DisplayIndex = orderedColumns.IndexOf(dataGridColumn);
               DisplayMetadataHelper.DisplayInfo displayInfo = DisplayMetadataHelper.GetDisplayInfo(entityMetadataType, dataGridColumn.Header as string);
               dataGridColumn.Header = displayInfo.DisplayName;
               if ((dataGridColumn is DataGridTextColumn) &&
                   (displayInfo.MaxLength.HasValue))
               {
                   int maxColumnLength = displayInfo.MaxLength.Value;
                   Style newStyle = new Style(typeof(TextBox), ((DataGridTextColumn)dataGridColumn).EditingElementStyle);
                   newStyle.Setters.Add(new Setter(TextBox.MaxLengthProperty, maxColumnLength));
                   ((DataGridTextColumn) dataGridColumn).EditingElementStyle = newStyle;
               }
           }
       }