views:

35

answers:

1

I have a RadGridView, a RadDataPager and a RadNumericUpDown all defined in code.

Now i want to bind the RadDataPager.PageSize to the RadNumericUpDown.Value so the pagesize of the pager is changeable via the RadNumericUpDown control.

Thus i try:

RadDataPager dataPager = new ...;
RadNumericUpDown pageSizeSelector = new ...;

Binding b = new Binding();
b.Mode = BindingMode.TwoWay;
b.Source = pageSizeSelector.Value;

pageSizeSelector.SetBinding(dataPager.PageSize, b);

But this generates an error about the dataPager.PageSize not being a DependencyProperty. What i'm a missing?

EDIT
Thanks to Klinger i got it straight. SetBinding wants the Static Definition of the DP, not a reference to the instance.

Binding b = new Binding("PageSize");
b.Mode = BindingMode.TwoWay;
b.Source = dataPager;
pageSizeSelector.SetBinding(RadNumericUpDown.ValueProperty, b);
A: 
Klinger
I know binding is possible. Telerik has a demo in which it is done in XAML.http://demos.telerik.com/silverlight/#DataPager/FirstLook and click on 'View Code'
Dribbel
@Dribbel: What they did is the other way around. The binding expression is set in the NumericUpDown, not in the DataPager. They are binding the NumericUpDown.Value to the DataPager.PageSize property, not the DataPager.PageSize to the NumericUpDown.Value . In their example the DataPager is the DataContext for the ConfigurationPanel and is set in code behind. If I am not mistaken, you could also get the same result using ElementName in the NumericUpDown binding expression.
Klinger
The otherway around also doesn't work, pageSizeSelector.Value also isn't a dependencyProperty. I'm lost...CODE: Binding b = new Binding("PageSize"); b.Mode = BindingMode.TwoWay; b.Source = dataPager.PageSize; dataPager.SetBinding(pageSizeSelector.Value, b);
Dribbel
@Dribbel: Try: CODE: Binding b = new Binding("PageSize"); b.Mode = BindingMode.TwoWay; b.Source = dataPager; pageSizeSelector.SetBinding(RadNumericUpDown.Value, b);
Klinger
Thanks, i got my understandings of bindings in code wrong. Now it works.
Dribbel