Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
here is the below code i have written for textbox when i loss focus on it it must work and check for validation using idataerrorinfo.without using command if i bind viewmodel its working for evry change of element ie..every time its going to background code .here how to work with command .after lossing focus on that control it must check for validation.

What I have tried:

 <TextBox Grid.Row="2" Name="MN" Grid.Column="1" Width="200" Height="30" DataContext="{StaticResource ViewModel}"
Text="{Binding Mobilenumber,Mode=TwoWay}" >
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="LostFocus">
                    <i:InvokeCommandAction Command="{Binding Mobilenumber}" CommandParameter="{Binding ElementName=MN,Path=Text}" >

                    </i:InvokeCommandAction>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBox>
Posted
Updated 25-Oct-17 21:40pm

1 solution

You don't need commands to do this, the binding will do it for you. You have the TextBox binding configured (by default) to update the viewmodel on loss of focus.

You can read more here: [^]
 
Share this answer
 
Comments
saimanisha 26-Oct-17 3:57am    
i used the below code for binding.but the style which we have applied to show error content and s=error symbol is getting applied even when we are not running the window.
<TextBox Grid.Row="3" Grid.Column="1" Width="200" Height="30" DataContext="{Binding Source={StaticResource ViewModel}}"
Text="{Binding Path=Emailid,Mode=TwoWay,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}" />
Graeme_Grant 26-Oct-17 4:05am    
That is a different problem to the question asked. The question was about LostFocus, not validation. Please close of this question and start a new one.
saimanisha 26-Oct-17 5:17am    
can you please answer for the question what i have aske dabout validation when window is not running .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900