0

I'm attempting to bind to a readonly property on a third party control (so no control over the implementation of the property). As I understand, I need to do this as a onewaytosource binding type, and also need to do it in code.

I have the following code to set the binding:

            Binding svBinding = new Binding();
        svBinding.Path = new PropertyPath("SurfaceScrollViewer");
        svBinding.Source = DataContext;
        svBinding.Mode = BindingMode.OneWayToSource;
        Ds.SetBinding(DiagramSurface.ScrollViewerProperty, svBinding);

And my property implementation on the view model:

public DiagramScrollViewer SurfaceScrollViewer
    {
        get
        {
            return surfaceScrollViewer;
        }
        set
        {
            surfaceScrollViewer = value;
        }
    }

    private DiagramScrollViewer surfaceScrollViewer;

I can access other properties in the same data context by code, but for some reason, I cannot get this property to bind. Can anyone see where I'm going wrong?

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
richzilla
  • 40,440
  • 14
  • 56
  • 86

2 Answers2

0

It doesn't work, because it is a bug of wpf. Take a look of this http://meleak.wordpress.com/2011/08/28/onewaytosource-binding-for-readonly-dependency-property/

Eugene Petrov
  • 651
  • 1
  • 5
  • 14
0

Hi I misunderstood your question Sorry. It is a kind of bug in wpf for binding ReadOnly properties with OneWayToSource BindingMode you can get exact answer for this is here

Community
  • 1
  • 1
yo chauhan
  • 12,079
  • 4
  • 39
  • 58
  • This won't help because the Target is readonly. The idea is to have the property in the viewmodel updated when the property is changed. Not the other way around. – MikeKulls Jul 16 '12 at 04:08