Running data validation in WPF

I have a WPF issue with validation.
I have a custom control that has multiple text boxes that are bound to a datamodel.
Checking is done using IDataErrorInfo.

I only want validation to be performed when the user clicks the Submit Data button, so I used UpdateSourceTrigger="Explicit"

with binding all of these text fields.

Everything is working fine and validation is only triggered when the user clicks on the button where I update the data sources.

But this custom control can be hidden or shown, and when I change the visibility from display / to hidden and then back to display, validation is done.

Is there a way to control validation at this stage?

+2


source to share


1 answer


This is the code I am using

Linking to a text box

<TextBox
        AutomationProperties.AutomationId="StreetNameTextBoxId"
        Height="20" Margin="0,0,5,0" FontSize="12" Name="_streetNameText"
        AcceptsReturn="False" AcceptsTab="False" Focusable="True"
        Text="{Binding ElementName=_this, Path=SearchParameters.EnteredAddress, UpdateSourceTrigger=Explicit}">

      



Code that performs validation and search (which is associated with clicking a button called "Search")

 private void ExecuteSearch() { 
        _streetNameText.UpdateDataSource();
        if (ViewModel.CustomerSpecification.IsValid())
            PerformActionInBackground(delegate{PerformSearch();});
    }

      

0


source







All Articles