Click here to Skip to main content
12,394,573 members (76,298 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# WPF C#4.0 DataGrid
private void dataGrid1_AutoGeneratedColumns(object sender, EventArgs e)

          Style mystyle = new System.Windows.Style();
          Setter set = new Setter();
          set.Property = DependencyProperty.Register("TextAlignment", typeof(TextAlignment),
          mystyle.TargetType = typeof(TextBlock);
          set.Value = TextAlignment.Right;
          dataGrid1.AutoGenerateColumns = true;

           DataGridColumnHeader header =new DataGridColumnHeader();
           Style headerstyle = new System.Windows.Style();
          headerstyle.TargetType = header.GetType();
          Setter setter = new Setter();
          Setter setter1 = new Setter();
          Setter setter2 = new Setter();
          setter.Property = FontSizeProperty;
          FontSize = 15;
          setter.Value = FontSize;
          setter1.Property = ForegroundProperty;
          Foreground = Brushes.BlueViolet;
          setter1.Value = Foreground;
          Setter setter3 = new Setter();
          LinearGradientBrush lb = new LinearGradientBrush();
          Point startpoint=new Point(0.5,0);
          Point endpoint = new Point(1, 1);
          lb.StartPoint = startpoint;
          lb.EndPoint = endpoint;
          GradientStop gst = new GradientStop();
          lb.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
          lb.GradientStops.Add(new GradientStop(Colors.Orange, 0.5));
          lb.GradientStops.Add(new GradientStop(Colors.Red, 1.0));
          setter3.Property = BackgroundProperty;
          setter3.Value = lb;
        dataGrid1.HeaderStyle = headerstyle;

this code yield datagrid1 Headerstyle change . but the text alignment in the column can't be set it always lie on the left
what I have to do for this

any help is highly appreaciated
Posted 23-Jan-12 3:34am
Updated 24-Jan-12 3:06am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 24 Jan 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100