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

[Solved] How can you bind to ancestor properties from within a RadGridView.RowDetailsTemplate?

1 Answer 301 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Geoff Hardy
Top achievements
Rank 1
Geoff Hardy asked on 04 Mar 2010, 08:13 PM
We have a RadGridView that is bound to our main ViewModel. The RadGridView uses a RowDetailsTemplate containing numerous editable fields. One of these fields is a ComboBox which we wish to bind its ItemsSource to one of the properties on the main ViewModel (ie. the object that the grid is bound to). I have tried numerous things to reference the properties on the ViewModel from within the RowDetailsTemplate, such as:

<ComboBox DisplayMemberPath="Descr" ItemsSource="{Binding DataContext.Chairs,RelativeSource={RelativeSource TemplatedParent}}"/>

but nothing ever seems to show up in the ComboBox, despite the fact that the Chairs property on the main ViewModel has items in its list. Nothing shows up in the Visual Studio Output pane to say that the binding was not valid. I have also tried doing a binding using ElementName but had the same result.

Is it possible to bind to properties on objects outside the RowDetailsTemplate?

1 Answer, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 05 Mar 2010, 07:40 AM
Hi,

Here is an example how to achieve this:

XAML
<UserControl x:Class="SilverlightApplication1.MainPage"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    xmlns:local="clr-namespace:SilverlightApplication1"
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">
    <UserControl.Resources>
        <local:MyDataContext x:Key="context" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" DataContext="{StaticResource context}">
        <Grid.Resources>
            <local:MyDataContext x:Key="context" />
        </Grid.Resources>
        <telerikGrid:RadGridView ItemsSource="{Binding MyData}" RowDetailsVisibilityMode="Visible">
            <telerikGrid:RadGridView.RowDetailsTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="MyProperty:"/>
                        <TextBox DataContext="{StaticResource context}"
                                 Text="{Binding MyProperty}"/>
                    </StackPanel>
                </DataTemplate>
            </telerikGrid:RadGridView.RowDetailsTemplate>
        </telerikGrid:RadGridView>
    </Grid>
</UserControl>

You can check the attached application for reference.


Regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Geoff Hardy
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or