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

Bind dependency property in custom column not working

1 Answer 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas Sonnenschein
Top achievements
Rank 2
Thomas Sonnenschein asked on 28 Jul 2016, 08:17 AM

Hello,

  I try to set a dependency property in a gridviews custom column, based on GridViewBoundColumnBase, with binding to another field of my datasource. The problem is, that then the Int32 dependency property always is set with the int default value of 0 and not the actual value in my data. If I also show this field as additional column, I can see, that it is filled correct in the datasource.

When I set the dependency property with a fixed value (e.G. 2), this value is properly transferred to the custom column implementation. When I try binding, nothing is set in the custom column implementation. I also tried a nullable type for my property, than always the null value is set, if I try binding.

After intense internet research, studding examples and other people problems and resolutions, my implementation should work, but unfortunately it don't.

Here my code:

01.public class ActualValueInputColumn : GridViewBoundColumnBase
02.{
03.  public Int32 TestStepType
04.  {
05.    get { return (Int32) GetValue (TestStepTypeProperty); }
06.    set { SetValue (TestStepTypeProperty, value); }
07.  }
08.
09.  public static readonly DependencyProperty TestStepTypeProperty =
10.        DependencyProperty.Register ("TestStepType", typeof (Int32), typeof (ActualValueInputColumn), new PropertyMetadata (null));
11.
12.  public override FrameworkElement CreateCellEditElement (GridViewCell cell, object dataItem)
13.  {
14.    FrameworkElement picker = null;
15.    if (TestStepType == 0)
16.    {
17.      RadMaskedNumericInput numberPicker = new RadMaskedNumericInput ();
18.      numberPicker.SetBinding (RadMaskedNumericInput.ValueProperty, this.CreateValueBinding ());
19.      picker = numberPicker;
20.    }
21....
22.    else if (TestStepType == 2)
23.    {
24.      RadMaskedTextInput textPicker = new RadMaskedTextInput ();
25.      textPicker.SetBinding (RadMaskedTextInput.ValueProperty, this.CreateValueBinding ());
26.      picker = textPicker;
27.    }
28.
29.    return picker;
30.  }
31.
32.  public override object GetNewValueFromEditor (object editor)
33.  {
34.    ...
35.  }
36.
37.  private Binding CreateValueBinding ()
38.  {
39.    Binding valueBinding = new Binding ();
40.    valueBinding.Mode = BindingMode.TwoWay;
41.    valueBinding.NotifyOnValidationError = true;
42.    valueBinding.ValidatesOnExceptions = true;
43.    valueBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
44.    valueBinding.Path = new PropertyPath (this.DataMemberBinding.Path.Path);
45.
46.    return valueBinding;
47.  }
48.}

And by XAML (shortened):

 

01.<telerik:RadGridView x:Name="RadGridView1"
02.   telerik:StyleManager.Theme="Windows8Touch"
03.   ItemsSource="{Binding MeasuringMachineValues}"
04.   AutoGenerateColumns="False"
05.   ShowGroupPanel="False"
06.   IsFilteringAllowed="False"
07.   FontSize="18"
08.   CanUserDeleteRows="False"
09.   CanUserInsertRows="False">
10.  <telerik:RadGridView.Columns>
11.    <telerik:GridViewDataColumn Header="TestStepType"
12.             DataMemberBinding="{Binding TestStepType}"
13.             IsReadOnly="True"
14.    <qw:ActualValueInputColumn Header="Actual Value custom column"
15.             DataMemberBinding="{Binding ActualValueAsString, Mode=TwoWay}"
16.             TestStepType="{Binding TestStepType}"/>
17.    <telerik:GridViewDataColumn Header="Actual value standard"
18.             DataMemberBinding="{Binding ActualValueAsString}" />
19.  </telerik:RadGridView.Columns>
20.</telerik:RadGridView>

 

 

Please can anybody tell me, what is wrong with my implementation or even give me a hint, how to debug this binding to get a clue, where the problem is?

 

Greetings

  Thomas

1 Answer, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 01 Aug 2016, 11:42 AM
Hi Thomas ,

I have already replied you in your support ticket. In order to avoid double posting, I would kindly ask you to keep any further communication regarding this topic in it.

Regards,
Yoan
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Thomas Sonnenschein
Top achievements
Rank 2
Answers by
Yoan
Telerik team
Share this question
or