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

Converter={StaticResource myConverter} in c#

2 Answers 518 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 31 Dec 2010, 06:58 AM
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 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 03 Jan 2011, 08:27 AM
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
0
Tingting
Top achievements
Rank 1
answered on 16 Nov 2012, 03:58 PM
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.
Tags
GridView
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Tingting
Top achievements
Rank 1
Share this question
or