Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 593191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:49:10+00:00 2026-05-13T15:49:10+00:00

I have a dialog with a few fields. Some of them use validation –

  • 0

I have a dialog with a few fields. Some of them use validation – ValidatesOnExceptions=True in my case.

I have a data object with INotifyPropertyChanged that I bind to dialogs’ DataContext.

I also have a “Save” button. Validation works fine, but only after I edit each field.

If dialog is opened and closed immediately, validation will not fire.

What should I do prevent Save from firing in this case (use case: open dialog, press save immediately)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:49:11+00:00Added an answer on May 13, 2026 at 3:49 pm

    Use command bindings for the save button, then you can enable/disable the button depending on your current state

    see this simple tutorial and if you want further explantion the msdn article, also josh smith gets more in depth

    We handle your above situation by using a combination of commands and an IsValid property on the underlying model we are binding to. We do validation at the business model level (some times in the ui as well) and when the business model is valid we enable the command, or as in your case, save button.

    Here is a sample of the style we apply to our text boxes (we derive from text box and give it another property called SimpleField. This field has the properties IsValid, IsDirty, IsReadOnly, ErrorMessage and DatabaseValue. This enables us to know if the field is valid, whether it has changed if it is read only (i.e. the user doesnt have the permission to change the value or it is locked for another reason), if there is an error message (associated with the IsValid property) and also the database value (for when the field has changed, the user can see the original value) We use all of these properties in the style below

       <!-- Simple TextBox -->
       <Style
          TargetType="{x:Type local:SimpleFieldTextBox}"
          BasedOn="{StaticResource {x:Type TextBox}}">
          <Setter
             Property="KeyboardNavigation.TabNavigation"
             Value="None" />
          <Setter
             Property="FocusVisualStyle"
             Value="{x:Null}" />
          <Setter
             Property="AllowDrop"
             Value="True" />
          <Setter
             Property="SnapsToDevicePixels"
             Value="True" />
          <Setter
             Property="Height"
             Value="22" />
          <Setter
             Property="Template">
             <Setter.Value>
                <ControlTemplate
                   TargetType="{x:Type local:SimpleFieldTextBox}">
    
                   <Border
                      x:Name="PART_SimpleFieldTextBox"
                      Background="{TemplateBinding Background}"
                      BorderBrush="{TemplateBinding BorderBrush}"
                      BorderThickness="{TemplateBinding BorderThickness}"
                      Height="{TemplateBinding Height}"
                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
    
                      <Grid>
                         <Grid.ColumnDefinitions>
                            <ColumnDefinition
                               Width="Auto" />
                            <ColumnDefinition
                               Width="*" />
                         </Grid.ColumnDefinitions>
    
                         <!-- The implementation places the Content into the ScrollViewer.
                              It must be named PART_ContentHost for the control to function -->
                         <ScrollViewer
                            x:Name="PART_ContentHost"
                            Grid.Column="1"
                            Margin="0" />
    
    
                         <!-- Not Valid Icon -->
                         <Path
                            x:Name="IconError"
                            Grid.Column="0"
                            Fill="Red"
                            Stretch="Fill"
                            Margin="1,1,4,1"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Top"
                            Visibility="Collapsed"
                            Width="4"
                            Height="14"
                            SnapsToDevicePixels="True"
                            Data="M0,11 L6,11 6,14 0,14 z M0,0 L6,0 6,10 0,10 z">
                            <Path.ToolTip>
                               <ToolTip>
                                  <StackPanel
                                     Orientation="Vertical"
                                     MaxWidth="300"
                                     MaxHeight="100">
                                     <TextBlock
                                        FontStyle="Italic"
                                        Text="Error:" />
                                     <TextBlock
                                        Margin="8,0,0,0"
                                        TextWrapping="WrapWithOverflow"
                                        TextTrimming="CharacterEllipsis"
                                        Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SimpleField.ErrorMessage}" />
                                     <TextBlock
                                        Margin="0,4,0,0"
                                        FontStyle="Italic"
                                        Text="Original Value: " />
                                     <TextBlock
                                        Margin="8,0,0,0"
                                        TextWrapping="WrapWithOverflow"
                                        TextTrimming="CharacterEllipsis"
                                        Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SimpleField.DatabaseValue}" />
                                  </StackPanel>
                               </ToolTip>
                            </Path.ToolTip>
                         </Path>
    
    
                         <!-- Valid (but changed) Icon-->
                         <Path
                            x:Name="IconWarning"
                            Grid.Column="0"
                            Fill="#FF5BBD30"
                            Stretch="Fill"
                            Margin="1,1,0,0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Top"
                            Visibility="Collapsed"
                            Width="8"
                            Height="8"
                            SnapsToDevicePixels="True"
                            Data="M0,0 L8,0 0,8 z">
                            <Path.ToolTip>
                               <ToolTip>
                                  <StackPanel
                                     Orientation="Vertical"
                                     MaxWidth="500"
                                     MaxHeight="100">
                                     <TextBlock
                                        Text="Original Value: " />
                                     <TextBlock
                                        Margin="8,0,0,0"
                                        TextWrapping="Wrap"
                                        TextTrimming="CharacterEllipsis"
                                        Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SimpleField.DatabaseValue}" />
                                  </StackPanel>
                               </ToolTip>
                            </Path.ToolTip>
                         </Path>
                      </Grid>
                   </Border>
                   <ControlTemplate.Triggers>
    
                      <!-- Stop the text box being edited if the simple field is read only -->
                      <DataTrigger
                         Binding="{Binding RelativeSource={RelativeSource Self}, Path=SimpleField.IsReadOnly}"
                         Value="True">
                         <Setter
                            Property="IsReadOnly"
                            Value="True" />
                         <Setter
                            Property="Foreground"
                            Value="{StaticResource DisabledForegroundBrush}" />
                         <Setter
                            TargetName="PART_SimpleFieldTextBox"
                            Property="Background"
                            Value="{StaticResource DisabledBackgroundBrush}" />
                         <Setter
                            TargetName="PART_SimpleFieldTextBox"
                            Property="BorderBrush"
                            Value="{StaticResource DisabledBorderBrush}" />
                      </DataTrigger>
    
                      <!-- IsEnabled condition -->
                      <DataTrigger
                         Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}"
                         Value="False">
                         <Setter
                            Property="Foreground"
                            Value="{StaticResource DisabledForegroundBrush}" />
                         <Setter
                            TargetName="PART_SimpleFieldTextBox"
                            Property="Background"
                            Value="{StaticResource DisabledBackgroundBrush}" />
                         <Setter
                            TargetName="PART_SimpleFieldTextBox"
                            Property="BorderBrush"
                            Value="{StaticResource DisabledBorderBrush}" />
                      </DataTrigger>
    
                      <!-- When value inside field has been changed -->
                      <DataTrigger
                         Binding="{Binding RelativeSource={RelativeSource Self}, Path=SimpleField.IsDirty}"
                         Value="True">
                         <Setter
                            TargetName="IconWarning"
                            Property="Visibility"
                            Value="Visible" />
                      </DataTrigger>
    
                      <!-- When value inside field is NOT valid -->
                      <DataTrigger
                         Binding="{Binding RelativeSource={RelativeSource Self}, Path=SimpleField.IsValid}"
                         Value="False">
                         <Setter
                            TargetName="IconWarning"
                            Property="Visibility"
                            Value="Collapsed" />
                         <Setter
                            TargetName="IconError"
                            Property="Visibility"
                            Value="Visible" />
                      </DataTrigger>
                   </ControlTemplate.Triggers>
                </ControlTemplate>
             </Setter.Value>
          </Setter>
       </Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few combo-boxes and double spin boxes on my Qt Dialog. Now
I have a dialog box that allows users to set hotkeys for use in
Here's a use case: I have a desktop application (built using Eclipse RCP) which
I have a few linkbuttons that each open the save dialog to let users
I've few word documents with Mail merge in them, I have to change the
I have a custom dialog box displaying some text and a image underneath. The
i need some help here. I have a dialog box that contains an iFrame
I have a dialog where each entry in a JTree has its corresponding options
I have a dialog that resizes. It also has a custom background which I
I have a dialog in MFC with a CStatusBar. In a separate thread, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.