BindingExpressionBase::ValidateWithoutUpdate Method

Runs any ValidationRule objects on the associated Binding that have the ValidationStep property set to RawProposedValue or ConvertedProposedValue. This method does not update the source.

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)

public:
bool ValidateWithoutUpdate()

Return Value

Type: System::Boolean
true if the validation rules succeed; otherwise, false.

The ValidateWithoutUpdate method enables you to run validation rules on a binding without updating the source of the binding. This is useful when you want to validate user input and update the source at different times in an application.

For example, suppose you have a form to update a data source that contains a submit button. You want to provide feedback to the user if an invalid value is entered before the user attempts to submit the form. You can check the validity of a field by setting the binding's UpdateSourceTrigger property to Explicit and calling ValidateWithoutUpdate when the TextBox loses focus.

The following example demonstrates the scenario that is discussed in the Remarks section. The example enables a user to enter data for a library item and submit the data. The binding for the TextBox named callNum has a ValidationRule associated with it. When the TextBox loses focus, the example calls ValidateWithoutUpdate. When the user clicks the submit button, the example calls UpdateSource to commit the changes. The following XAML creates the user interface for the application.

<StackPanel>
    <StackPanel.Resources>
        <Style TargetType="HeaderedContentControl">
            <Setter Property="Margin" Value="2"/>
            <Setter Property="Focusable" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="HeaderedContentControl">
                        <DockPanel LastChildFill="False">
                            <ContentPresenter ContentSource="Header" DockPanel.Dock="Left" 
                              Focusable="False" VerticalAlignment="Center"/>
                            <ContentPresenter ContentSource="Content" Margin="5,0,0,0" 
                              DockPanel.Dock="Right" VerticalAlignment="Center"/>
                        </DockPanel>

                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

</StackPanel.Resources>
    <HeaderedContentControl Header="Title">
        <TextBox Width="150" Text="{Binding Path=Title, Mode=TwoWay}"/>
    </HeaderedContentControl>
    <HeaderedContentControl Header="Due Date">
        <TextBox Width="150" Text="{Binding Path=DueDate, StringFormat=d, Mode=TwoWay}">

        </TextBox>
    </HeaderedContentControl>

    <HeaderedContentControl Header="Call Number">
        <TextBox Name="CallNum" Width="150"
                 LostFocus="CallNum_LostFocus"
                 Validation.Error="CallNum_Error">
            <TextBox.Text>
                <Binding xmlns:src="clr-namespace:BindingExpressionBaseValidateWithoutUpdating"
                    Path="CallNumber" Mode="TwoWay"
                    NotifyOnValidationError="True"
                    UpdateSourceTrigger="Explicit">
                    <Binding.ValidationRules>
                        <src:CallNumberRule ValidationStep="ConvertedProposedValue"/>
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
    </HeaderedContentControl>

    <Button Click="Button_Click">Submit</Button>

    <HeaderedContentControl Header="Title">
        <TextBlock Text="{Binding Path=Title, Mode=TwoWay}"/>
    </HeaderedContentControl>

    <HeaderedContentControl Header="Due Date">
        <TextBlock Text="{Binding Path=DueDate, StringFormat=d, Mode=TwoWay}"/>
    </HeaderedContentControl>

    <HeaderedContentControl Header="Call Number">
        <TextBlock Text="{Binding CallNumber}"/>
    </HeaderedContentControl>

</StackPanel>

The following example shows the logic for the user interface.

No code example is currently available or this language may not be supported.

The following example shows the data object and ValidationRule for the application.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft