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

Color in codebehind(.vb)

3 Answers 47 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pan hal
Top achievements
Rank 1
Pan hal asked on 16 Oct 2009, 09:02 PM
This is bit different requirement.

Need to set the background color of grid with alternate colors. These colors are need to be set in Resource dictionary. and then used in .vb code. How to do this.
This is how I approched.

In resource disctionary  

<SolidColorBrush x:Key="oddrow" Color="Yellow"/>

 <SolidColorBrush x:Key="Evenrow" Color="blue"/>

In.vb   

Dim OddRowColor As New SolidColorBrush   

Dim EvenRowColor As New SolidColorBrush 

 

OddRowColor.Color = App.Current.Resources("oddrow")    

 EvenRow.Color = App.Current.Resources("Evenrow")
(This doesnot work , it throws error)
These colors will be used in below condition

 Grid.Background = IIf(some conditions, E

venRowColor,OddRowColor)


 

 

 

 

 

 

 

 



 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 19 Oct 2009, 04:11 PM
Hello Pan hal,

This blogpost illustrates 2 ways of controling row background color depending on some data conditions.
I believe the example can be easily adapted to fit your scenario.

Let me know if you find any troubles in the process.

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Pan hal
Top achievements
Rank 1
answered on 19 Oct 2009, 05:18 PM

Thanks but this is not the requirement. We have many clients and need to set different background color for alternate rows in the grid for different client . I have separate resource dictionary for each client where I will be setting this alternates colors and again in .vb will retrive this colors as

 

 OddRowColor.Color = App.Current.Resources("oddrow")    

 EvenRow.Color = App.Current.Resources("Evenrow")

This is where I'm struck. How to get  colors set in resource dictionary into .vb code.
 Is App.current.Resources("styles") is the right one ??
Please help me.


0
Pavel Pavlov
Telerik team
answered on 22 Oct 2009, 02:29 PM
Hi Pan hal,

Provided that you have the following App.XAML :
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="alternatingColorsSample.App"
             xmlns:gridview="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
             >
    <Application.Resources>
        <Style TargetType="gridview:GridViewRow" x:Key="altRowStyle">
            <Setter Property="Background" Value="Green" />
        </Style>
    </Application.Resources>
</Application>

You may set it to RadGridView the following way:

this.RadGridView1.AlternateRowStyle = App.Current.Resources("altRowStyle")

* you may need to cast  the item to Style .

Let me know if you need a sample project demonstrating the approach.

Sincerely yours,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Pan hal
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Pan hal
Top achievements
Rank 1
Share this question
or