Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Validate XamDatagrid cell in WPF using MVVM/C#
posted

Iam using XamDatagrid in WPF using MVVM/C#. I have an editable column in the grid with EditModeStart/End commands. These commands have 'get' methods where the code does something just before the starting and ending of a grid cell. Now I want to validate the cell value to make sure its between -100 and 100 with an alert box else I shoudnt permit the user to do anything on the WPF view.

Can someone please help me out?  FYI, All my code is in viewmodel only.

Many thanks in advance,

Ravi

  • 1915
    Verified Answer
    posted

    The simplest way to do it in MVVM way is have an attached property hooked up to the CellUpdated routed event in the class on a VM side that will execute an ICommand (like RoutedCommand) on the ViewModel class when the cell's updated and cell exits edit mode. Then, you do your processing/validation within the RoutedCommand method and depending on how you hooked up your Msgbox handle the validation results. See Brian Laguna's blog for details: http://brianlagunas.com/an-mvvm-friendly-property-for-the-xamdatapresenter-doubleclick-event/