Welcome to the Xceed Community | Help
Community Search  
More Search Options

setting the font color {style} of a column in the wpf datagrid

Sort Posts: Previous Next
  •  02-06-2009, 11:11 AM Post no. 18452

    setting the font color {style} of a column in the wpf datagrid

    Hi,

    I am using the wpf datagrid in virtualizationmode = true; mode. How can I change the font color {style} of a particular column?

    many thanks

    Peter 

     

    Filed under:
  •  02-06-2009, 1:43 PM Post no. 18459 in reply to 18452

    Re: setting the font color {style} of a column in the wpf datagrid

    Hi Peter,

    You can change the background color of a particular column by Styling the DataCells and the ColumnManagerCell of your data grid with a Trigger that has for condition the FieldName set to the field name of the Column of interest and a Setter to the Property Background with the desired color.


    Xceed - Software Developer and Technical Support
  •  02-07-2009, 7:31 AM Post no. 18473 in reply to 18459

    Re: setting the font color {style} of a column in the wpf datagrid

    Hi Mohamed,

    I am new with the datagrid for wpf:( can you help me with some example code? If i can manage the font color of a column I am going to buy the grid.

     many thanks

    Peter

  •  02-09-2009, 2:00 PM Post no. 18491 in reply to 18473

    Re: setting the font color {style} of a column in the wpf datagrid

    Hi Peter, 

    The following sample shows you how to set the background color of the DataCells, to blue, of the Column ShipVia :

     i.e.:

     

    <Style TargetType="{x:Type xcdg:DataCell}">

    <Style.Triggers>

    <DataTrigger Binding="{Binding RelativeSource={RelativeSource self}, Path=ParentColumn.FieldName}" Value="ShipVia">

    <Setter Property="Background" Value="Blue" />

    </DataTrigger>

    </Style.Triggers>

    </Style>

     

     


    Xceed - Software Developer and Technical Support
  •  02-09-2009, 4:42 PM Post no. 18496 in reply to 18491

    Re: setting the font color {style} of a column in the wpf datagrid

    Hi Mohamed,

     The Background color works:) many thanks. But the font color (Foreground) doesn't:(

    Style style = new Style(typeof(DataCell));

    // Setter setter = new Setter(DataCell.BackgroundProperty, Brushes.Red);

     

    Setter setter = new Setter( DataCell.ForegroundProperty, Brushes.Red);

    style.Setters.Add(setter);

    this.grid.Resources[typeof(DataCell)] = style;

    Is it possible to set the font color for a column?

     Thanks

    Peter

  •  02-11-2009, 4:56 PM Post no. 18562 in reply to 18496

    Re: setting the font color {style} of a column in the wpf datagrid

    Hi Peter,

    I was able to change the font color of my data cells using your code snippet, so it definately is possible to do it.

    If you make a sample application that reproduces the issue and send it to support@xceed.com, we can try to investigate it further.

    (please include a link to this forum thread in your email)

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  03-24-2009, 9:51 AM Post no. 19561 in reply to 18562

    Re: setting the font color {style} of a column in the wpf datagrid

    Hi i have a OrderID field in my grid so i write this code to change the grid row color basen on it's value but it is not working please help

     

    Style style = new Style(typeof(Xceed.Wpf.DataGrid.DataRow ));
                DataTrigger styleDataTrigger = new DataTrigger();
                System.Windows.Data.Binding binding = new System.Windows.Data.Binding("OrderID");
                styleDataTrigger.Binding = binding;
                styleDataTrigger.Value = "10249";
                style.Triggers.Add(styleDataTrigger);
                Setter setter = new Setter(Xceed.Wpf.DataGrid.DataRow.BackgroundProperty, Brushes.Yellow  );
                style.Setters.Add(setter);
                this.dataGridControl.Resources[typeof(Xceed.Wpf.DataGrid.DataRow)] = style;

  •  03-24-2009, 10:07 AM Post no. 19563 in reply to 19561

    Re: setting the font color {style} of a column in the wpf datagrid

    When using a Trigger (or DataTrigger), you need to put the Setter on the Trigger and not on the Style:

      Style style = new Style(typeof(Xceed.Wpf.DataGrid.DataRow ));
      DataTrigger styleDataTrigger = new DataTrigger();
      System.Windows.Data.Binding binding = new System.Windows.Data.Binding("OrderID");
      styleDataTrigger.Binding = binding;
      styleDataTrigger.Value = "10249";
      Setter setter = new Setter(Xceed.Wpf.DataGrid.DataRow.BackgroundProperty, Brushes.Yellow  );
      styleDataTrigger.Setters.Add( setter );
      style.Triggers.Add(styleDataTrigger);
      this.dataGridControl.Resources[typeof(Xceed.Wpf.DataGrid.DataRow)] = style;

     


    ** Quick Tip: Clients with an active support subscription should be sending their questions by email if they wish to benefit from the faster response time. Thanks!


    Diane Lafontaine
    Technical Support
    Xceed Software Inc.
  •  03-25-2009, 2:20 AM Post no. 19596 in reply to 19563

    Re: setting the font color {style} of a column in the wpf datagrid

    Hi

    I have tried ur suggession and i call this code in initialized even of my grid but it is not working even now for more clarity i am using a datatable to bind the grid which have this orderId field and i am loading the data in constuctor of my class on which i have the grid placed Like

     

    DataSet dataSet = new DataSet();

    string mdbFile = @"Data\Northwind.mdb";

    string connString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile);

    OleDbConnection conn = new OleDbConnection(connString);

    OleDbDataAdapter adapter = new OleDbDataAdapter();

    adapter.SelectCommand = new OleDbCommand("SELECT * FROM Orders;", conn);

    adapter.Fill(dataSet, "Orders");

    m_orders = dataSet.Tables["Orders"];

    m_orders.Columns.Add("Check");

    m_orders.Columns["Check"].Caption = "Hello";

    //m_orders.Columns["Check"].DefaultValue = "Hello";

     

    dataGridControl.ItemsSource = new DataGridCollectionView(TryXcGrid.Orders.DefaultView);

    ===============Xaml============== 

    <xcdg:DataGridControl x:Name="dataGridControl" MinHeight="200" Loaded="xamDataGrid1_Loaded"

    Initialized="xamDataGrid1_Loaded1"

    Margin="16.5,0,20,-138">

    </xcdg:DataGridControl>

     Please Help i am stuck from last 2 days or send a similar code if possible

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.