Difference between revisions of "Windows Presentation Foundation"

From Richard's Wiki
Jump to: navigation, search
 
(11 intermediate revisions by the same user not shown)
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/]:
 +
 +
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;
 +
                }
 +
            }
 +
        }
 +
 +
 +
* [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://joshsmithonwpf.wordpress.com/a-guided-tour-of-wpf/ A Guided Tour of WPF - A simple introduction to WPF]
 
* [http://joshsmithonwpf.wordpress.com/a-guided-tour-of-wpf/ A Guided Tour of WPF - A simple introduction to WPF]
 
* [http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms WPF Tutorial - Using WPF In WinForms]
 
* [http://www.switchonthecode.com/tutorials/wpf-tutorial-using-wpf-in-winforms WPF Tutorial - Using WPF In WinForms]
 +
* [http://codeblitz.wordpress.com/2009/05/08/wpf-validation-made-easy-with-idataerrorinfo/ WPF: Validation made easy with IDataErrorInfo]
 
* [http://msdn.microsoft.com/en-us/magazine/cc700358.aspx Customize Data Display with Data Binding and WPF (How to display errors, handle IDataErrorInfo)]
 
* [http://msdn.microsoft.com/en-us/magazine/cc700358.aspx Customize Data Display with Data Binding and WPF (How to display errors, handle IDataErrorInfo)]
 
* [http://www.longhorncorner.com/Blogs/BlogDetail.aspx?BlogId=1481 Silverlight and XAML Namespace Declarations]
 
* [http://www.longhorncorner.com/Blogs/BlogDetail.aspx?BlogId=1481 Silverlight and XAML Namespace Declarations]
 +
* [[media:WpfCustomBindingClass.zip]] Example Custom WPF Binding Class VS2008 Project
 +
 +
* [http://blog.raffaeu.com/archive/2009/11/01/build-enterprise-application-with-wpf-wcf-entity-framework-and-prism-yet-again.aspx Value and business validation with Enterprise Library 4.1 and Entity Framework (and WPF)]
 +
 +
* [http://stackoverflow.com/questions/793100/globally-catch-exceptions-in-a-wpf-application Globally catch exceptions in a WPF application]

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;
               }
           }
       }