Confirmation dialog on bool Cell Edit (MVVM)

5 posts, 1 answers
  1. iahulg
    iahulg avatar
    7 posts
    Member since:
    Jan 2016

    Posted 18 Apr Link to this post

    Hello. 
    I have boolean column in my grid with custom checkbox template:

    <telerik:GridViewDataColumn Header="Custom Bool Column"
                       EditTriggers="CellClick"
                       DataMemberBinding="{Binding LabelReady, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                       HeaderTextAlignment="Center">
       <telerik:GridViewColumn.CellTemplate>
          <DataTemplate>
             <Image Height="20" Margin="2"  Stretch="Uniform">
                <Image.Style>
                   <Style TargetType="{x:Type Image}">
                      <Setter Property="Source" Value="/red-cross.png"/>
                         <Style.Triggers>
                            <DataTrigger Binding="{Binding LabelReady}" Value="True">
                               <Setter Property="Source" Value="/green-tick.png"/>
                            </DataTrigger>
                         </Style.Triggers>
                      </Style>
                   </Image.Style>
                </Image>
             </DataTemplate>
          </telerik:GridViewColumn.CellTemplate>
       </telerik:GridViewDataColumn>

    And I need to add a confirmation dialog on cell edit using MVVM approach, i.e. now when user double clicks on the image, the value is changed to opposite, how can I add a dialog, which will ask user if he really wants to change the value, and change the value in cell only if he press "Yes" ? 

     

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    281 posts

    Posted 21 Apr Link to this post

    Hello Vitali,

    You can use the Telerik EventToCommandBehavior in order to keep the MVVM pattern for your application. Eventually, you can use it to bind the "Click"(or any other) event of the CheckBox in the CellEditTemplate of your column to a custom command in your ViewModel. 

    I have added a sample project that suggests a possible scenario. Please review it and consider taking a similar approach at your end. 

    Regards,
    Stefan Nenchev
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. iahulg
    iahulg avatar
    7 posts
    Member since:
    Jan 2016

    Posted 21 Apr in reply to Stefan Nenchev Link to this post

    Hi, Stefan !
    Thanks for your help. The solution looks pretty elegant. 
    Can the same be achieved without entering cell edit mode, i.e. just by (double) clicking on readonly cell ? 
  5. Answer
    Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    281 posts

    Posted 22 Apr Link to this post

    Hi,

    You can use a ToggleButton instead of a CheckBox and predefine its Control Template. Please review the updated sample. You can consider such approach at your end and apply some further customizations.

    Regards,
    Stefan Nenchev
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. iahulg
    iahulg avatar
    7 posts
    Member since:
    Jan 2016

    Posted 22 Apr Link to this post

    Thanks again, Stefan. 
    It worked well for me)
Back to Top
UI for WPF is Visual Studio 2017 Ready