This is a migrated thread and some comments may be shown as answers.

[Solved] Grid - DataColumn - Text Color

12 Answers 479 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark
Top achievements
Rank 1
Mark asked on 08 Nov 2010, 02:23 AM
My appologies but I've just not been able to figure this out.

When I explicitely create DataColumns in DataGrid the text is coming is showing white.  The ComboBox's are the correct black.
How can I correct the DataColumns?  I've applied no themes or changes.  I've attached a screenshot and code behind below

Thanks,
Mark

private void buildChildGrid()
        {
  
            var cboColumn = new GridViewComboBoxColumn();
            var cboColumn1 = new GridViewComboBoxColumn();
            var cboColumn2 = new GridViewComboBoxColumn();
            var cboColumn3 = new GridViewComboBoxColumn();
            var txtColumn = new GridViewDataColumn();
            var txtColumn2 = new GridViewDataColumn();
            var txtColumn3 = new GridViewDataColumn();
            var txtColumn4 = new GridViewDataColumn();
            var chkColumn1 = new GridViewCheckBoxColumn();
  
  
            {
                txtColumn.UniqueName = "unitQtyColumn";
                  
                txtColumn.DataMemberBinding = new Binding ("unitQty");
                txtColumn.DataMemberBinding.Mode = BindingMode.TwoWay;
                //txtColumn.Binding.Mode = BindingMode.TwoWay;
                txtColumn.Header = "Qty";
                txtColumn.SortMemberPath = "unitQty";
                txtColumn.Width = 40;
                  
                //txtColumn.Width = new C1.Silverlight.DataGrid.DataGridLength(40);
            }
  
  
            {
                cboColumn.ItemsSource = qryOriginVarietalDomainDataSource.Data;
                cboColumn.DisplayMemberPath = "oriVar";
                cboColumn.SelectedValueMemberPath = "varietalID";
                cboColumn.UniqueName = "cboVarietalIDColumn";
                cboColumn.Header = "Origin - Varietal";
                cboColumn.DataMemberBinding = new Binding("varietalID");
                cboColumn.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn.SortMemberPath = "varietalID";
  
            }
  
            {
                cboColumn1.ItemsSource = tblGradeDomainDataSource.Data;
                cboColumn1.DisplayMemberPath = "gradeName";
                cboColumn1.SelectedValueMemberPath = "gradeID";
                cboColumn1.UniqueName = "gradeIDColumn";
                cboColumn1.Header = "Grade";
                cboColumn1.DataMemberBinding = new Binding("gradeID");
                cboColumn1.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn1.SortMemberPath = "gradeID";
  
            }
  
            {
                txtColumn2.UniqueName = "unitPriceColumn";
                txtColumn2.DataMemberBinding = new Binding("unitPrice");
                txtColumn2.DataMemberBinding.Mode = BindingMode.TwoWay;
                txtColumn2.Header = "Unit Price";
                txtColumn2.SortMemberPath = "unitPrice";
                txtColumn2.Width = 80;
            }
  
            {
                txtColumn3.UniqueName = "transDescColumn";
                txtColumn3.DataMemberBinding = new Binding("transDesc");
                txtColumn3.DataMemberBinding.Mode = BindingMode.TwoWay;
                txtColumn3.Header = "Chop - Mark";
                txtColumn3.SortMemberPath = "transDesc";
            }
  
            {
                cboColumn2.ItemsSource = tblLocationDomainDataSource.Data;
                cboColumn2.DisplayMemberPath = "location";
                cboColumn2.SelectedValueMemberPath = "locationID";
                cboColumn2.UniqueName = "cboLocationColumn";
                cboColumn2.Header = "Point of Purchase";
                cboColumn2.DataMemberBinding = new Binding("poLocID");
                cboColumn2.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn2.SortMemberPath = "poLocID";
            }
  
            {
                chkColumn1.UniqueName = "chkCertColumn";
                chkColumn1.Header = "Cert";
                chkColumn1.DataMemberBinding = new Binding("isCert");
                chkColumn1.DataMemberBinding.Mode = BindingMode.TwoWay;
                chkColumn1.SortMemberPath = "isCert";
                chkColumn1.Width = 40;
            }
  
            {
                List<string> dropDownLoad_ArabicaRobusta = new List<string>();
                dropDownLoad_ArabicaRobusta.Add("Arabica");
                dropDownLoad_ArabicaRobusta.Add("Robusta");
                cboColumn3.ItemsSource = dropDownLoad_ArabicaRobusta;
                cboColumn3.UniqueName = "cboArabicaRobustaColumn";
                cboColumn3.Header = "Species";
                cboColumn3.DataMemberBinding = new Binding("robArab");
                cboColumn3.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn3.SortMemberPath = "robArab";
  
  
            }
            {
                dg_tblPOLines.Columns.Add(txtColumn);
                dg_tblPOLines.Columns.Add(cboColumn);
                dg_tblPOLines.Columns.Add(cboColumn3);
                dg_tblPOLines.Columns.Add(cboColumn1);
                dg_tblPOLines.Columns.Add(chkColumn1);
                dg_tblPOLines.Columns.Add(txtColumn2);
                dg_tblPOLines.Columns.Add(txtColumn3);
                dg_tblPOLines.Columns.Add(cboColumn2);
            }
        }

12 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 10 Nov 2010, 09:28 AM
Hello Mark,

 Can you verify if there are not implicit styles in this application for TextBlock?

Sincerely yours,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 10 Nov 2010, 01:59 PM
Hello Vanya,

Ahh of course, that makes perfect sense.  Yes the solution is using JetPack.  The standard textblock picks up the full Microsoft theme including the background while the textblock in your control doesn't.

Is there any easy solution for this?

[Picture:]
Top left - standard grid
Top right - Telerik Grid
Bottom left - text block

Thanks,
Mark 
0
Vanya Pavlova
Telerik team
answered on 11 Nov 2010, 04:18 PM
Hello Mark,

Generally the Microsoft Themes cannot be applied to our RadControls. JetPack theme uses an implicit style that is applied to all TextBlock elements. RadGridView uses TextBlock's in its CellTemplates, in this way you are getting white foreground in each GridViewCell. In order to maintain JetPack theme as a global theme in your application and to use the default behavior of GridViewCell you should ignore the global style in GridViewColumn's CellTemplate using the following markup:

<telerik:RadGridView  Margin="40,60,67,90"  ItemsSource="{Binding Collection}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Property1" DataMemberBinding="{Binding Property1}">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Property1}" Style="{x:Null}"/>
                        </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

As an alternative you should explicitly set the Foreground property of the TextBlock, that resides in GridViewDataColumn's CellTemplate.

Best wishes,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 11 Nov 2010, 06:20 PM
Thank you, would it be possible to provide a code behind example of the explicitly set the Foreground property ?
The other consideration is that it is really the text color that needs normalization, not the cell color.
0
Vanya Pavlova
Telerik team
answered on 16 Nov 2010, 04:35 PM
Hello Mark,


Once you have defined a DataTemplate for your GridViewData column you can easily access GridViewCells (internally uses a TextBlock element) using ChildrenOfType<> extension method and just change its foreground property.

Please see the attached example and let me know if you need any further assistance.

All the best,
Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Mark
Top achievements
Rank 1
answered on 16 Nov 2010, 04:59 PM
Hello Vanya,

Thank you for your efforts but unfortunately you are still working in the XAML with your example. 
Is it not possible to handle the process within the code behind?

Thanks,
Mark
0
Mark
Top achievements
Rank 1
answered on 24 Nov 2010, 02:30 PM
Should I assume that we are limited to XAML in this case as I haven't heard back from you?
0
Vanya Pavlova
Telerik team
answered on 26 Nov 2010, 11:02 AM
Hello Mark,


Are you generating your columns in code behind? In the previous example the CellTemplate was defined in xaml and after that in code-behind I changed the foreground of this TextBlock. If you are generating your columns in code behind just refer the CellTemplate in code behind as a Resource, because that is recommended approach.


I am really a bit confused and it could be great If you can share a little bit more info about this issue.


All the best,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Mark
Top achievements
Rank 1
answered on 26 Nov 2010, 12:01 PM
Hi Vanya,

Thank you for your reply.  Yes, if you'll look at the beginning of the post, you'll see I'm trying to do everything from code behind.  Any example using just a code behind solution would be appreciated.

Regards,
Mark
0
Vanya Pavlova
Telerik team
answered on 29 Nov 2010, 04:26 PM
Hi Mark,


Please refer to following example:

MainPage.xaml:

<UserControl
    x:Class="DynamicColumns.MainPage"
    Width="640" Height="480">
    <UserControl.Resources>
        <DataTemplate x:Key="dt">
            <StackPanel>
                <!--<Explicilty set TextBlock's foreground property>-->
                <TextBlock Text="{Binding Property1}" Foreground="Red"/>
                <!--<As an alternative ignore the styles in this way as it was shown before, you can do the same in code behind>-->
                <!--<TextBlock Text="{Binding Property1}" Style="{x:Null}"/>-->
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
        <telerik:RadGridView x:Name="grid" Margin="55,65,74,100" AutoGenerateColumns="False" ItemsSource="{Binding Collection}"/>
        <telerik:RadButton Width="100" Height="35" Margin="5" Click="RadButton_Click" VerticalAlignment="Bottom" Content="Create column"/>
    </Grid>
</UserControl>

MainPage.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Data;
 
namespace DynamicColumns
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            // Required to initialize variables
            InitializeComponent();
        }
 
        private void RadButton_Click (object sender, RoutedEventArgs e)
        {
            /*The first column Named "col1" loads its CellTemplate through 
            a resource named "dt" defined in UserControls' Resources*/
            GridViewDataColumn col1 = new GridViewDataColumn();
            col1.Header = "Dynamic column";
            col1.CellTemplate = (DataTemplate)this.Resources["dt"];
            col1.DataMemberBinding = new Binding("Property1");
            this.grid.Columns.Add(col1);
            /*The second column Named "col2" loads its CellTemplate  dynamically through XamlReader
            /in Silverlight it is recommended to define DataTemplates in a Resource Collection
            /as it was shown in the first column Named "col1"
            but you can also use this approach using XamlReader*/
            GridViewDataColumn col2 = new GridViewDataColumn();
            col2.Header = "Another dynamic column";
            var template = (DataTemplate)XamlReader.Load( @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""><TextBlock Text=""{Binding Property1}"" Foreground=""Blue"" /></DataTemplate>");
            col2.CellTemplate = template;
            col2.DataMemberBinding = new Binding("Property1");
            this.grid.Columns.Add(col2);
        }
    }
}


Please let me know how this works in your case.

Greetings,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Mark
Top achievements
Rank 1
answered on 29 Nov 2010, 04:28 PM
HI Vanya,

Thanks for your efforts, this is what I was lokoing for.
I sincerely appreicate you taking the time to put it together.

Rgrds,
Mark
0
Kevin Burandt
Top achievements
Rank 1
answered on 03 Jan 2011, 07:08 PM
One way to change this globally is to modify the textblock style for the theme in CoreStyles.xaml from this:

<!-- Text Styles. -->
 <Style TargetType="TextBlock">
     <Setter Property="Foreground" Value="{StaticResource NormalFontBrush}" />
</Style>

To this:

<!-- Text Styles. -->
 <Style TargetType="TextBlock">
     <Setter Property="Foreground" Value="Black" />
</Style>

I'm not sure what it will to the rest of your app but the MS themes usually specify a style whenever a textblock is used so you may be okay.

Kevin
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Mark
Top achievements
Rank 1
Kevin Burandt
Top achievements
Rank 1
Share this question
or