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

Binding Background of a Cell

3 Answers 616 Views
GridView
This is a migrated thread and some comments may be shown as answers.
R
Top achievements
Rank 1
R asked on 21 Aug 2010, 11:02 AM
Hi,
In Telerik WPF Help file, in  Getting Started of RadGridView, there is a very simple sample.
Yeah it's too simple for my needs, so I add a Background property to Employee Class as follow:

public SolidColorBrush Background { set; get; }

Then in XAML, Changed say, <telerikGrid:GridViewDataColumn DataMemberBinding="{Binding LastName}" Header="Last Name"/>
to
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding LastName}" Background="{Binding Background} Header="Last Name" />
But nothing happened :(

In some googling I come to some promising samples like:

<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding LastName}">
                    <telerikGrid:GridViewDataColumn.Background>
                        <SolidColorBrush Color="{Binding Background}"/>
                    </telerikGrid:GridViewDataColumn.Background>
                </telerikGrid:GridViewDataColumn>

But unfortunately it didn't work either.
Any suggestions?
Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
R
Top achievements
Rank 1
answered on 21 Aug 2010, 09:03 PM
Okay, That was a bit you-know-what-I-mean question.
Actually I was somewhat out of mood when dealing with that problem.
Now that I'm in better mood it seems that this problem was pretty easy:

<telerik:GridViewDataColumn Header="Test"  Width="50*"><br>                    <telerik:GridViewDataColumn.CellTemplate>
<
DataTemplate>                        
<
TextBlock Text="{Binding Value}"  Background="{Binding Background}" Margin="0" />                                                                                 </DataTemplate>                   
</
telerik:GridViewDataColumn.CellTemplate>               
</
telerik:GridViewDataColumn>           
</
telerik:RadGridView.Columns

0
Paul
Top achievements
Rank 1
answered on 16 Sep 2020, 05:31 PM
It works but in my case there is a margin. I want the background color to take up the full height (stretch). How can I set the background color of the cell (via binding) where there is no padding/margin (e.g. full height of row)? Thanks.
0
Vladimir Stoyanov
Telerik team
answered on 21 Sep 2020, 07:06 AM

Hello Paul,

Can you check out the Change the Color of GridViewCell Based on a Property's Value article in our documentation? It demonstrates how you can achieve this requirement by utilizing a style targeting GridViewCell.

I hope you find this helpful.

Regards,


Vladimir Stoyanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Tags
GridView
Asked by
R
Top achievements
Rank 1
Answers by
R
Top achievements
Rank 1
Paul
Top achievements
Rank 1
Vladimir Stoyanov
Telerik team
Share this question
or