Hi,
I saw this Xaml code in this forum:
<igGrid:XamWebGrid Name="xamWebGrid1"> <igGrid:XamWebGrid.Columns> <igGrid:TextColumn Key="Value1"> <igGrid:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="1Some looooong text that should be split in multiline " TextWrapping="Wrap" Width="120"/> </DataTemplate> </igGrid:TextColumn.HeaderTemplate> </igGrid:TextColumn> <igGrid:TextColumn Key="SomeLongPropertyNameThatWillBeWrappedInTheGridHeader"> <igGrid:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding}" TextWrapping="Wrap" Width="120"/> </DataTemplate> </igGrid:TextColumn.HeaderTemplate> </igGrid:TextColumn>
</igGrid:XamWebGrid.Columns> </igGrid:XamWebGrid>
I would like to convert to C# but I don't know how I can add/insert a datatemplate to hold the textblock.
xamWebGrid1.Columns.Add(new TextColumn() { Key = "Value1", HeaderText = "SomeLongPropertyNameThatWillBeWrappedInTheGridHeader", Width = new ColumnWidth(85, false), IsReadOnly = false, });
Can anyone help? Thanks!
The attached sample shows exactly this. Basically, you'd want to bind the TextBlock text to your column's key (the name of your column).
This is done by just binding the TextBlock to the DataContext:
Hope this helps,
Hi Georgi,
Thank you for your response. Using resource file I am able to add button event but here the problem is I want to change my TextBlock Text which is in the Resource file along with Button. I am not able to change the Text. I want to give the Column Name to textBlock Text.
Thanks
Check if the attached solution works for you. It uses a DataTemplate added to page's resources and the column is generated in code-behind in page's Loaded event.
Hi ptilwani,
There is no straightforward way to add an event handler to event in DataTemplate in Silverlight. Here a link I found in google containing a brief discussion on this matter.
HTH
I am creating the TextColumn at runtime and adding it to the Grid from ViewModel. I want add HeaderTemplate to TextColumn. I want to add one Button and one TextBlock to headerTemplate at runtime and for the Button I want to add an event. I am able to add the button but if i add Click Event its throwing an exception saying we can not add Event to it. I
tried one more way of doing this. In the Xaml i created a DataTemplate with Button and TextBlock. and I am adding this datatemplate to Grid TextColumn HeaderTemplate. But before adding to TextColumn HeaderTemplate I want to change the TextBlock Text, I want to display the Column Name for that TextBlock. I am finding the Textblock control from the codebehind and changing its Text. But in UI its not updating the Text. Can you please help me in this.
What I want is adding the HeaderTemplate to TextColumn from codebehind and that HeaderTemplate will contain one Image Button and one textBlock. Button is to open a new popupwindow and TextBlock is to display column header.