Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > Set Cell Template Image code behind

Answered Set Cell Template Image code behind

Feed from this thread
  • Colin avatar

    Posted on Feb 8, 2012 (permalink)

    If I have the following column in a radgrid, could someone help me with code behind on how to set the image source programtically based on a column value?

    <telerik:GridViewColumn Header="Notes" Width="50">

    <telerik:GridViewColumn.CellTemplate>

    <DataTemplate>

    <telerik:RadButton Name="btnObj" Height="25" Width="25" Click="btnObj_Click">

    <telerik:RadButton.Content>

    <Image Name="imgNotes" Source="/Images/notes.png" Height="16" Width="16" />

    </telerik:RadButton.Content>

     

    </telerik:RadButton>

    </DataTemplate>

    </telerik:GridViewColumn.CellTemplate>

    Reply

  • Vanya Pavlova Vanya Pavlova admin's avatar

    Posted on Feb 8, 2012 (permalink)

    Hi Colin,

     

    The recommended approach to achieve this result is through defining CellTemplateSelector.
    Have you checked our DataTemplateSelector demos?
    The same is applicable to WPF as well. 



    Greetings,
    Vanya Pavlova
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Colin avatar

    Posted on Feb 14, 2012 (permalink)

    Thanks for the link however I am still stuggling. I have implented the following class and added the resources to my page as below. But I cannot see how to set the style to the radribbonbutton that is within my datatemplate of the cell in my grid.

     

     

      public class NotesButtonStyle : StyleSelector
        {
            public override Style SelectStyle(object item, DependencyObject container)
            {
                if (item is OBJECTIVEALL)
                {
                    OBJECTIVEALL row = item as OBJECTIVEALL;

                    if (row.ManagerNotes == null && row.EmployeeNotes == null)
                        return NoNotes;
                    else
                        return HasNotes;
                       

                }
                return null;
            }

            public Style HasNotes { get; set; }
            public Style NoNotes { get; set; }
        }

     

     

        <UserControl.Resources>
            <local:RatingMatcherStyle x:Key="ratingMatcherStyle">
                <local:RatingMatcherStyle.RatingMisMatch>
                    <Style TargetType="telerik:GridViewCell">
                        <Setter Property="Foreground" Value="Red"></Setter>
                    </Style>
                </local:RatingMatcherStyle.RatingMisMatch>
            </local:RatingMatcherStyle>

            <local:NotesButtonStyle x:Key="notesButtonStyle">
                <local:NotesButtonStyle.HasNotes>
                    <Style TargetType="telerik:RadRibbonButton">
                        <Setter Property="SmallImage" Value="/Images/notes_empty.png"/>
                    </Style>
                </local:NotesButtonStyle.HasNotes>
                <local:NotesButtonStyle.NoNotes>
                    <Style TargetType="telerik:RadRibbonButton">
                        <Setter Property="SmallImage" Value="/Images/notes.png"/>
                    </Style>
                </local:NotesButtonStyle.NoNotes>
            </local:NotesButtonStyle>
        </UserControl.Resources>

     

     

     

     

     

     

    Reply

  • Vlad Vlad admin's avatar

    Posted on Feb 14, 2012 (permalink)

    Hi,

     According your first reply you have RadButton not RadRibbonButton. Can you clarify?

    Greetings,
    Vlad
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Colin avatar

    Posted on Feb 14, 2012 (permalink)

    sorry its a radribbonbutton I am using

    Reply

  • Colin avatar

    Posted on Feb 17, 2012 (permalink)

    Its a RadRibbonButton. Any chance you could advise please?

    Reply

  • Answer Tina Stancheva Tina Stancheva admin's avatar

    Posted on Feb 17, 2012 (permalink)

    Hello Colin,

    I believe in your case it would be better to create a converter instead of a StyleSelector. This would allow you to apply a Style on the RadRibbontButton based on your custom logic. I attached a sample project to demonstrate this approach. Please give ti a try and let me know if it works for you.

    All the best,
    Tina Stancheva
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
    Attached files

    Reply

  • Colin avatar

    Posted on Feb 17, 2012 (permalink)

    You are a genius!! Worked Perfectly many thanks

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > Set Cell Template Image code behind
Related resources for "Set Cell Template Image code behind"

WPF Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]