locked
No DependencyObject.SetCurrentValue in WinRT? RRS feed

  • Question

  • Hello, 

    I'm developing cross-platform controls for WPF, Silverlight and WinRT. There is a condition where you need to set a DependencyProperty value without updating its ValueSource. In WPF4 we can achieve this by calling DependencyObject.SetCurrentValue(). 

    There is a discussion and sample you can download to demonstrate the effectiveness of DependencyObject.SetCurrentValue() in WPF4. 

    Now SetCurrentValue does not exist in either WinRT or Silverlight. How am I supposed to set a DependencyProperty value in code without overriding its value source? It causes havoc when a consumer of the control writes DataTemplates that set properties via bindings. The local CLR property which I must set in code in my custom control overwrites the existing binding, or, if set before the binding is set, causes it to never be applied to the control. 

    Note: TwoWay binding won't work in this case. We need SetCurrentValue in WinRT.


    Sunday, November 17, 2013 1:01 PM

All replies

  • Thanks for the request. You are correct that this method is available only in WPF 4 and 4.5

    --Rob

    Sunday, November 17, 2013 4:18 PM
    Moderator
  • Hi Rob, 

    Yes, I know, but my question is what can I do instead when I need this functionality? 

    I've just solved a problem in a Custom Control I'm building by using SetCurrentValue. Unfortunately because this is not available in Silverlight or WinRT, it means on both these platforms I either need consumers of this control to live with the bug (unacceptable), or develop a workaround. 

    In this specific case I was able to workaround by using a Binding in code, but sometimes that is not possible. Sometimes you need to just 'set a DependencyProperty value' without overwriting the ValueSource (which is what SetCurrentValue does). 

    I'd like to request Microsoft puts this at least in their WinRT framework. Else it will be very hard to port controls to this platform. 

    Best regards, 
    Andrew

    Sunday, November 17, 2013 6:03 PM