Color in codebehind(.vb)

4 posts, 0 answers
  1. Pan hal
    Pan hal avatar
    61 posts
    Member since:
    Aug 2009

    Posted 16 Oct 2009 Link to this post

    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)


     

     

     

     

     

     

     

     



     

     

     

     

     

     

  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 19 Oct 2009 Link to this post

    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.
  3. Pan hal
    Pan hal avatar
    61 posts
    Member since:
    Aug 2009

    Posted 19 Oct 2009 Link to this post


    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.


  4. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 22 Oct 2009 Link to this post

    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.
Back to Top