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

    Hi

    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>

    Thanks
    Rich

    <Grid.Resources>
                <local:MyConverter x:Key="myConverter" />
    </Grid.Resources>

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

    </telerik:GridViewDataColumn>


    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
    Admin
    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

    Hello, 

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

     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