Guest User

Untitled

a guest
Jul 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. private static DataGridTextColumn GetTextColumn(string ColumnName, string FormatString, bool AlignRight)
  2. {
  3. DataGridTextColumn c = new DataGridTextColumn();
  4. c.Header = Test.Common.UIBizObjectCache.LocalizedText.GetLocalizedText(ColumnName);
  5. c.Binding = new System.Windows.Data.Binding(ColumnName);
  6. if (!string.IsNullOrWhiteSpace(FormatString))
  7. c.Binding.StringFormat = FormatString;
  8. if (AlignRight)
  9. {
  10. Style cellRightAlignedStyle = new Style(typeof(DataGridCell));
  11. cellRightAlignedStyle.Setters.Add(new Setter(DataGridCell.HorizontalAlignmentProperty, HorizontalAlignment.Right));
  12. c.CellStyle = cellRightAlignedStyle;
  13. }
  14.  
  15. //var buttonTemplate = new FrameworkElementFactory(typeof(Button));
  16. //buttonTemplate.Text = "X";
  17. //buttonTemplate.AddHandler(
  18. // Button.ClickEvent,
  19. // new RoutedEventHandler((o, e) => HandleColumnHeaderButtonClick(o, e))
  20. // );
  21. //c.HeaderTemplate=new DataTemplate(){VisualTree = buttonTemplate};
  22.  
  23. return c;
  24. }
  25.  
  26. string colProperty = "Name";
  27.  
  28. DataGridTextColumn col = new DataGridTextColumn();
  29. col.Binding = new Binding(colProperty);
  30. var spHeader = new StackPanel() { Orientation = Orientation.Horizontal };
  31. spHeader.Children.Add(new TextBlock(new Run(colProperty)));
  32. var button = new Button();
  33. button.Click += Button_Filter_Click;
  34. button.Content = "Filter";
  35. spHeader.Children.Add(button);
  36. col.Header = spHeader;
  37.  
  38. dataGrid.Columns.Add(col);
Add Comment
Please, Sign In to add comment