Can you set a default binding between two properties of a control? RRS feed

  • Question

  • Let's say I want to create a NumericUpDown control that has a ValueText property that is effectively the current Value.ToString().

    There is also a DisplayText property that is the text that will actually be displayed. By default I want a simple binding between ValueText and DisplayText, so that the default it to simply display the text version of the current value.

    Now if we want to display something more complex (say, units, a non-linear scale, etc) then we want to be able to remove that default binding and add our own binding or value converter.

    So to clarify:

    ValueText  [binding]-> DisplayText

    Value [custom binding]-> DisplayText

    Alternatively, is there a better MVVM solution to accomplish what I need?

    Sunday, July 20, 2014 6:00 PM


  • So, you want to be able to customize the view of the control?  It seems like you could have a Boolean property that set "ShowDefaultView" to true or false and then displays that appropriately. If set to false, the user could get access to the Value as a property and run it through a converter.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Monday, July 21, 2014 1:33 PM