We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

xaml to code

Thread ID:

Created:

Updated:

Platform:

Replies:

143362 Mar 15,2019 05:33 PM UTC Mar 19,2019 11:01 AM UTC WPF 1
loading
Tags: SfDataGrid
John
Asked On March 15, 2019 05:33 PM UTC

How can I convert this xaml to C# code ?

                                        <syncfusion:GridTextColumn Width="50" MappingName="NameHere" >
                                            <syncfusion:GridTextColumn.HeaderTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="Some Text" TextWrapping="Wrap" TextAlignment="Center" />
                                                </DataTemplate>
                                            </syncfusion:GridTextColumn.HeaderTemplate>
                                            <syncfusion:GridTextColumn.CellStyle>
                                                <Style TargetType="syncfusion:GridCell">
                                                    <Setter Property="BorderThickness" Value="0"/>
                                                    <Setter Property="Background">
                                                        <Setter.Value>
                                                            <MultiBinding Converter="{StaticResource ConverterName}">
                                                                <Binding />
                                                                <Binding Path="NameHere"/>
                                                            </MultiBinding>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </syncfusion:GridTextColumn.CellStyle>
                                        </syncfusion:GridTextColumn>

Deivaselvan Y [Syncfusion]
Replied On March 19, 2019 11:01 AM UTC

Hi Xmen,

Thank you for contacting Syncfusion support.

You can refer the below code example for your given XAML code to C# code. Try this code example and let us know if this helps you.

 
//Example to create DataTemplate in code behind 
FrameworkElementFactory textblock = new FrameworkElementFactory(typeof(TextBlock)); 
textblock.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Center); 
textblock.SetValue(TextBlock.TextProperty, "Some Text"); 
textblock.SetValue(TextBlock.TextWrappingProperty, TextWrapping.Wrap); 
DataTemplate headerTemplate = new DataTemplate() { VisualTree = textblock }; 
 
//Example to create MutiBindig in code behind 
MultiBinding multiBinding = new MultiBinding(); 
multiBinding.Converter = (BackgroundColorConverter)this.Resources["ConverterName"]; 
multiBinding.Bindings.Add(new Binding() { Path = new PropertyPath("") }); 
multiBinding.Bindings.Add(new Binding() { Path = new PropertyPath("NameHere") }); 
 
//Example to create Style in code behind 
Style cellStyle = new Style(typeof(Syncfusion.UI.Xaml.Grid.GridCell)); 
Setter borderThickness = new Setter(GridCell.BorderThicknessProperty, new Thickness(0)); 
Setter background = new Setter(GridCell.BackgroundProperty, multiBinding); 
cellStyle.Setters.Add(borderThickness); 
cellStyle.Setters.Add(background); 
 
//Add TextColumn to the DataGrid 
this.datagrid.Columns.Add(new GridTextColumn() { MappingName = "NameHere", HeaderTemplate = headerTemplate, CellStyle = cellStyle }); 

Regards,
Deivaselvan 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;