Hello,
create a new Silverlight 5 application and replace MainPage.xaml, with:
Run the application: the header of the column is empty, but should be the text of the Text TextBox.
In some more complex scenario, the header text is set to the path of the DataMemberBinding (MyProperty here)!
Patrick
create a new Silverlight 5 application and replace MainPage.xaml, with:
<
UserControl
x:Class
=
"Test_DataGrid_Binding.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignWidth
=
"640"
d:DesignHeight
=
"480"
>
<
Grid
Margin
=
"5"
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"Auto"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
TextBlock
Name
=
"Text"
Text
=
"TextBlock text"
/>
<
telerik:RadGridView
AutoGenerateColumns
=
"False"
Grid.Row
=
"1"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding MyProperty}"
Header
=
"{Binding Text, ElementName=Text}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
</
Grid
>
</
UserControl
>
Run the application: the header of the column is empty, but should be the text of the Text TextBox.
In some more complex scenario, the header text is set to the path of the DataMemberBinding (MyProperty here)!
Patrick
6 Answers, 1 is accepted
0
Hi Patrick,
For your convenience I have prepared a sample project, please find it attached.
I believe this helps.
Greetings,
Yoan
the Telerik team
Instead of setting binding directly to the header property , please try using HeaderCellStyle. Check the following XAML:
<
UserControl.Resources
>
<
my:MyViewModel
x:Key
=
"MyViewModel"
/>
<
DataTemplate
x:Key
=
"HeaderTemplate"
>
<
TextBlock
Text
=
"{Binding Text, ElementName=TextBox1}"
/>
</
DataTemplate
>
</
UserControl.Resources
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
>
<
telerik:GridViewDataColumn.HeaderCellStyle
>
<
Style
TargetType
=
"telerik:GridViewHeaderCell"
>
<
Setter
Property
=
"ContentTemplate"
Value
=
"{StaticResource HeaderTemplate}"
/>
</
Style
>
</
telerik:GridViewDataColumn.HeaderCellStyle
>
</
telerik:GridViewDataColumn
>
For your convenience I have prepared a sample project, please find it attached.
I believe this helps.
Greetings,
Yoan
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 09 Nov 2012, 03:27 PM
Yoan,
it works, but with your solution I need to define a DataTemplate and the HeaderCellStyle for each column on the GridView!
The binding for the header works perfectly if we don't use the ElementName property of the binding, so it should be a bug in the RadGridView.
The final use in my case is I have a control that returns the text of a resource from the name of the resource, via a converter.
I need a control because binding directly to a static resource will lead to memory leak (the binding is never removed by Silverlight). With the control I can use the Loaded and Unloaded events to add / remove the binding. This scenarion works really well.. except for the GridView headers.
----Remove comment above----
|Note: if I define a class that descend from GridViewDataColumn, the binding work perfectly!
----------------------------------------
Patrick
it works, but with your solution I need to define a DataTemplate and the HeaderCellStyle for each column on the GridView!
The binding for the header works perfectly if we don't use the ElementName property of the binding, so it should be a bug in the RadGridView.
The final use in my case is I have a control that returns the text of a resource from the name of the resource, via a converter.
I need a control because binding directly to a static resource will lead to memory leak (the binding is never removed by Silverlight). With the control I can use the Loaded and Unloaded events to add / remove the binding. This scenarion works really well.. except for the GridView headers.
----Remove comment above----
|Note: if I define a class that descend from GridViewDataColumn, the binding work perfectly!
----------------------------------------
Patrick
0
Hi Patrick,
Please check this troubleshooting guide for a reference.
Yoan
the Telerik team
Please check this troubleshooting guide for a reference.
Yoan
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 14 Nov 2012, 12:45 PM
Yoan,
I now understand why it's not working with ElementName binding, but you should document this as a remark in the GridViewColumn.Header property documentation.
Now I need to find another way to express that I want, because I can't have to write all this XAML code for each column (more than 1000 columns in about 40 gridview's and there are other to come...)
Patrick
I now understand why it's not working with ElementName binding, but you should document this as a remark in the GridViewColumn.Header property documentation.
Now I need to find another way to express that I want, because I can't have to write all this XAML code for each column (more than 1000 columns in about 40 gridview's and there are other to come...)
Patrick
0
Edward
Top achievements
Rank 1
answered on 27 Mar 2013, 02:58 PM
That was what I thought, so thanks for providing a confirmation.
However. how would you bind to both a ElementName and the DataMember of the column?
However. how would you bind to both a ElementName and the DataMember of the column?
0
Hello,
Didie
the Telerik team
To Patrick: Thank you for your suggestion. We will add this remark to the API reference.
To Edward: I am not sure that I can understand your question, would you please clarify?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.