/// <summary> /// Creates the grid control. /// </summary> /// <param name="property">The property.</param> /// <returns> /// The control. /// </returns> protected virtual FrameworkElement CreateGridControl(PropertyItem property) { var c = new DataGrid { CanDelete = property.ListCanRemove, CanInsert = property.ListCanAdd, InputDirection = property.InputDirection, IsEasyInsertByMouseEnabled = property.IsEasyInsertByMouseEnabled, IsEasyInsertByKeyboardEnabled = property.IsEasyInsertByKeyboardEnabled, AutoGenerateColumns = property.Columns.Count == 0 }; foreach (var cd in property.Columns) { if (cd.PropertyName == string.Empty && property.ListItemItemsSource != null) { cd.ItemsSource = property.ListItemItemsSource; } c.ColumnDefinitions.Add(cd); } c.SetBinding(DataGrid.ItemsSourceProperty, property.CreateBinding()); return(c); }
/// <summary> /// Creates the grid control. /// </summary> /// <param name="property">The property.</param> /// <returns> /// The control. /// </returns> protected virtual FrameworkElement CreateGridControl(PropertyItem property) { var c = new DataGrid { CanDelete = property.ListCanRemove, CanInsert = property.ListCanAdd, InputDirection = property.InputDirection, EasyInsert = property.EasyInsert, AutoGenerateColumns = property.Columns.Count == 0 }; var glc = new GridLengthConverter(); foreach (var ca in property.Columns.OrderBy(cd => cd.ColumnIndex)) { var cd = new ColumnDefinition { PropertyName = ca.PropertyName, Header = ca.Header, FormatString = ca.FormatString, Width = (GridLength)(glc.ConvertFromInvariantString(ca.Width) ?? GridLength.Auto), IsReadOnly = ca.IsReadOnly }; if (ca.PropertyName == string.Empty && property.ListItemItemsSource != null) { cd.ItemsSource = property.ListItemItemsSource; } switch (ca.Alignment.ToString(CultureInfo.InvariantCulture).ToUpper()) { case "L": cd.HorizontalAlignment = HorizontalAlignment.Left; break; case "R": cd.HorizontalAlignment = HorizontalAlignment.Right; break; default: cd.HorizontalAlignment = HorizontalAlignment.Center; break; } c.ColumnDefinitions.Add(cd); } c.SetBinding(DataGrid.ItemsSourceProperty, property.CreateBinding()); return(c); }