Converter={StaticResource myConverter} in c#

3 posts, 0 answers
  1. Richard Harrigan
    Richard Harrigan avatar
    235 posts
    Member since:
    Nov 2009

    Posted 31 Dec 2010 Link to this post


    The following code extract is from Examples.GridView.DataFormatting.
    I need to do the highlighted xaml in c# code-behind.  Following the extract is my lame attempt at the code-behind.  Can you show me how to write the code-behind>


                <local:MyConverter x:Key="myConverter" />

    <telerik:GridViewDataColumn Header="Discontinued" DataMemberBinding="{Binding Discontinued}">
                                <TextBlock Text="{Binding Discontinued, Converter={StaticResource myConverter}}" />


    public class MyConverter : IValueConverter
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
                return ((bool) value) ? "yes" : "no";

            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
                return value;

    my code-behind
    gridViewDataColumn.DataMemberBinding = new Binding(col.UniqueName);
    TextBlock Text = new TextBlock();
    Binding binding = new Binding(col.UniqueName);
    binding.Path = new PropertyPath("Global.YesNoConverter");
    Text.SetBinding(TextBlock.TextProperty, binding);
    ?????? gridViewDataColumn.CellTemplate ???????????
  2. Vanya Pavlova
    Vanya Pavlova avatar
    2019 posts

    Posted 03 Jan 2011 Link to this post

    Hi Richard,

    I have prepared an example for you that demonstrates different approaches you may use to achieve the desired result. Please see the attached project and let me know if you need any further assistance.
    Thank you!

    Kind regards,
    Vanya Pavlova
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. Tingting
    Tingting avatar
    14 posts
    Member since:
    May 2012

    Posted 16 Nov 2012 Link to this post


     Here is my code xaml.  
    <telerik:GridViewDataColumn TextAlignment="Left" IsReadOnly="True"
                    Header="Etat" HeaderTextAlignment="Center" Width="*" UniqueName="etat">
              <DataTemplate x:Name="etatCell">
                   <Image x:Name="imageEtat" Source="{Binding Mode=OneWay, Converter={StaticResource EtatToImageConverter}}" Width="50" Height="50" />

     I want to know how to bind the converter whitch is in the DataTemplate  in the code behind.  So that i can change the converter dynamically.
Back to Top