This question is locked. New answers and comments are not allowed.
Hi,
I'm having a similar issue to http://www.telerik.com/forums/elementname-binding-inside-of-celltemplate but now I'm speaking Win 8 Store Apps.
I have a RadDataGrid where I want to bind a value from outside of its scope. (Actually this is a much simplified example.) Should this work?
Best regards,
Erik
I'm having a similar issue to http://www.telerik.com/forums/elementname-binding-inside-of-celltemplate but now I'm speaking Win 8 Store Apps.
I have a RadDataGrid where I want to bind a value from outside of its scope. (Actually this is a much simplified example.) Should this work?
<
TextBlock
x:Name
=
"MyTextBlock"
Text
=
"Test"
/>
<
telerikGrid:RadDataGrid
ItemsSource
=
"{Binding MyList}"
>
<
telerikGrid:RadDataGrid.Columns
>
<
telerikGrid:DataGridTemplateColumn
SizeMode
=
"Fixed"
Header
=
"MyHeader"
>
<
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Text, ElementName=MyTextBlock}"
></
TextBlock
>
</
DataTemplate
>
</
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
</
telerikGrid:DataGridTemplateColumn
>
</
telerikGrid:RadDataGrid.Columns
>
</
telerikGrid:RadDataGrid
>
Best regards,
Erik
5 Answers, 1 is accepted
0
Hi Erik,
Thank you for the question.
It is not possible to use an ElementName Binding in a DataTemplate. A possible solution is to bind both elements to a common property of your view model.
Let us know if you have further questions.
Regards,
Rositsa Topchiyska
Telerik
Thank you for the question.
It is not possible to use an ElementName Binding in a DataTemplate. A possible solution is to bind both elements to a common property of your view model.
Let us know if you have further questions.
Regards,
Rositsa Topchiyska
Telerik
0

Erik
Top achievements
Rank 1
answered on 20 Feb 2014, 09:31 AM
Hi,
Ok, but I can't seem to get how that works also, see this code. How can I bind the textblock-text to the outer viewmodel, when the datagrid has its own DataContext (MyList, which is also in the ViewModel). Is it by using FindAncestor somehow?
Best regards,
Erik
Ok, but I can't seem to get how that works also, see this code. How can I bind the textblock-text to the outer viewmodel, when the datagrid has its own DataContext (MyList, which is also in the ViewModel). Is it by using FindAncestor somehow?
<
telerikGrid:RadDataGrid
ItemsSource
=
"{Binding MyList}"
>
<
telerikGrid:RadDataGrid.Columns
>
<
telerikGrid:DataGridTemplateColumn
SizeMode
=
"Fixed"
Header
=
"MyHeader"
>
<
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding ParentViewModel??.MyText}"
></
TextBlock
>
</
DataTemplate
>
</
telerikGrid:DataGridTemplateColumn.CellContentTemplate
>
</
telerikGrid:DataGridTemplateColumn
>
</
telerikGrid:RadDataGrid.Columns
>
</
telerikGrid:RadDataGrid
>
Best regards,
Erik
0
Hello Erik,
Thank you for the question.
I can suggest you two possible solutions:
I hope this helps. Please, let us know if you have other questions.
Regards,
Rositsa Topchiyska
Telerik
Thank you for the question.
I can suggest you two possible solutions:
- If your view model is defined as a static resource, there is no problem with binding.
- You can introduce a new property in your data class that returns a property from the view model, although the logic in this case is a bit more complicated.
I hope this helps. Please, let us know if you have other questions.
Regards,
Rositsa Topchiyska
Telerik
0

Erik
Top achievements
Rank 1
answered on 21 Feb 2014, 01:58 PM
Thanks, having the ViewModel as a property in my data object will work for me!
I find it strange that it is not possible to "walk up the tree", and bind to a parents DataContext.
Cheers,
Erik
I find it strange that it is not possible to "walk up the tree", and bind to a parents DataContext.
Cheers,
Erik
0
Hello Erik,
I am glad one of the solutions worked for you. The ElementName Binding in the template of the column cell is not available in the RadDataGrid control due to some perfomace optimizations done. In the future we will consider possibilities of how this could be enabled.
Let us know if you have any other questions.
Regards,
Rositsa Topchiyska
Telerik
I am glad one of the solutions worked for you. The ElementName Binding in the template of the column cell is not available in the RadDataGrid control due to some perfomace optimizations done. In the future we will consider possibilities of how this could be enabled.
Let us know if you have any other questions.
Regards,
Rositsa Topchiyska
Telerik