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

binding to radgridview's parent datacontext

2 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michele
Top achievements
Rank 2
Michele asked on 07 Jun 2012, 07:27 AM
Hello,
I would like to know if it's possible for a  calculated column to access to the parent's context... I need to calulate over a parameter that's inside the main viewmodel..... I've tried to do 

<telerik:GridViewDataColumn Header="Calculated Max"
                  DataMemberBinding="{Binding Converter={StaticResource calculatedColumnConverter},ConverterParameter={Binding RelativeSource={RelativeSource AncestorType= Grid}}}"></telerik:GridViewDataColumn>

but I got an exception 

{System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at System.Windows.Data.BindingBase.CheckCanReceiveMarkupExtension(IProvideValueTarget provideValueTarget, DependencyObject& targetDependencyObject, DependencyProperty& targetDependencyProperty)
   at System.Windows.Data.BindingBase.ProvideValue(IServiceProvider serviceProvider)
   at MS.Internal.XamlManagedRuntimeRPInvokes.TryApplyMarkupExtensionValue(Object target, XamlPropertyToken propertyToken, Object& value)
   at 

How can I do that?
Thanks

2 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 07 Jun 2012, 10:22 AM
Hi Paolo,

From within the cell you can get access to the row DataContext  rather than the original view model . For such cases as yours we strongly recommend to expose your view model as static resource and use binding to this static resource.

All the best,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michele
Top achievements
Rank 2
answered on 07 Jun 2012, 10:37 AM
Helo Pavel,
thanks for your reply....I can't expose the viewmodel since I'm with Caliburn Micro.... so it resolves it automatically
I'll try to put the value I need into the Datacontext's item...I don't like this but I cannot find another solution...
Tags
GridView
Asked by
Michele
Top achievements
Rank 2
Answers by
Pavel Pavlov
Telerik team
Michele
Top achievements
Rank 2
Share this question
or