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

Binding To Dependency Object

2 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 03 Aug 2010, 10:58 PM
I know this is more of a general Silverlight question but since it is in reference to a Blog post from Vladmir I thought I would ask here. I am trying to implement his method for binding the SelectedItems property of a GridView to my own collection but I need to setup the binding programmatically. Here is the binding in question:

<telerik:RadGridView ItemsSource="{Binding Data}" SelectionMode="Extended" SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
    <i:Interaction.Behaviors>
        <local:MyMultiSelectBehavior SelectedItems="{Binding SelectedItems, Source={StaticResource context}}" />
    </i:Interaction.Behaviors>
</telerik:RadGridView>

What I'm a little bit unclear about is how to bind the SelectedItems of the MyMultiSelectBehavior to the SelectedItems of the data context since  MyMultiSelectBehavior is only a DependencyObject and does not contain the SetBinding method. Any help would be greatly appreciated.

Thanks,
Chris

2 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 04 Aug 2010, 01:23 PM
Hello Chris,

Here is how you can create the same binding in code:

var selectBehavior = new MyMultiSelectBehavior();
BindingOperations.SetBinding(selectBehavior, MyMultiSelectBehavior.SelectedItemsProperty,
 new Binding("SelectedItems") { Source = this.LayoutRoot.DataContext });
Interaction.GetBehaviors(this.myGrid).Add(selectBehavior);


Sincerely yours,
Milan
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
0
Chris
Top achievements
Rank 1
answered on 04 Aug 2010, 08:06 PM
Thanks!
Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Milan
Telerik team
Chris
Top achievements
Rank 1
Share this question
or