0

I have problem with creating a control which will be king of InPlaceEdit and which will handle validation.

Before I was thinking about validation I have created a control, which has dependency property:

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
    "Value",
    typeof (object),
    typeof (InPlaceEdit),
    new FrameworkPropertyMetadata(default (object), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ValueChanged));

And I have additional property for storing local (unchanged) value:

public static readonly DependencyProperty LocalValueProperty = DependencyProperty.Register(
    "LocalValue", 
    typeof (object), 
    typeof (InPlaceEdit), 
    new FrameworkPropertyMetadata(default(object), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

I have created buttons Save and Cancel which saving 'LocalValue' to binded property on save and restores 'LocalValue' from 'Value' on cancel.

It's working perfectly, but I have one problem with it. It does not support validation, because my binded value is changing on button click.

Is there a way to pass validation from ViewModel to my control somehow?

Tomasz
  • 2,051
  • 3
  • 31
  • 64
  • *to pass validation from ViewModel to my control* - how exactly you imagine that? You can assign callback method or you can provide all needed information to the control, so that it can *validate value itself*. But in general validation of data occurs in your ViewModel property setter. So.. what exactly do you want to happens and why *my binded value is changing on button click* is the problem? – Sinatr Jun 23 '15 at 12:01
  • _But in general validation of data occurs in your ViewModel property setter_ I cannot handle that in my code. I think, in this case I need to re-write my controls. My problem is that right now validation is happening after `Save` button is clicked. I would like to disallow clicking Save button is value is not valid. – Tomasz Jun 23 '15 at 12:05
  • [This](http://stackoverflow.com/q/231052/1997232) question sounds exactly as your problem. – Sinatr Jun 23 '15 at 12:13

0 Answers0