Validation error tooltip sync ???

Oct 28, 2013 at 9:21 AM
Edited Oct 28, 2013 at 9:26 AM
Validation error tooltip is not synchronizing with user control's navigation animation.
This is appearing only loading the login view.

How I can solve this ???
Oct 28, 2013 at 7:51 PM
Edited Oct 28, 2013 at 7:55 PM
Ok I did solve the problem. First I added a Property (DoValidate) my viewmodel and then I create a EventToCommand interaction trigger under the my nickname textbox
then I gave TextChanged event to EventToCommand. The DoValiateCommand triggered then IDataErrorInfo's property indexer worked like a charm :-)
public class LoginViewModel : ViewModelBase , IDataErrorInfo
    {
        private readonly ISession _session;
        private string _nickName;
        private string _password;
        private bool _isEnableButton;
        private bool _doValidate;

        public LoginViewModel(ISession session)
        {
            _session = session;
            LoginCommand = new RelayCommand(Login);
            DoValidateCommand = new RelayCommand(() =>
            {
                DoValidate = true;
            });
            DoValidate = false;
        }
        
        __//I just added this property and my problem gone to far away__
        public bool DoValidate
        {
            get { return _doValidate; }
            set
            {
                _doValidate = value; 
                RaisePropertyChanged(() => DoValidate);
            }
        }

        public string NickName
        {
            get { return _nickName; }
            set
            {
                _nickName = value;
                RaisePropertyChanged(() => NickName);
               
            }
        }

        public string Password
        {
            get { return _password; }
            set
            {
                _password = value;
                RaisePropertyChanged(() => Password);
            }
        }

        private void Login()
        {
            var user = _session.QueryOver<User>()
                .Where(x => x.NickName == this.NickName && x.Password == Password)
                .SingleOrDefault();
            if (user != null)
                MessengerInstance.Send(new NavigationMessage<User>("/Pages/Home.xaml", user));
            else
                MessengerInstance.Send(new NavigationMessage("/Pages/Settings.xaml"));
        }

        public ICommand LoginCommand { get; set; }

        public bool IsEnableButton
        {
            get { return _isEnableButton; }
            set
            {
                _isEnableButton = value; 
                RaisePropertyChanged(() => IsEnableButton);
            }
        }

        public string this[string columnName]
        {
            get
            {
                if (!DoValidate) return null;
                if (columnName == "NickName")
                {
                    if (string.IsNullOrEmpty(NickName))
                        return "Kullanıcı adı boş bırakılamaz.";
                }
                if (columnName == "Password")
                {
                    if (string.IsNullOrEmpty(Password))
                        return "Lütfen şifrenizi giriniz.";
                }
                return string.Empty; 
            }
        }

        public string Error { get; private set; }

        public ICommand DoValidateCommand
        {
            get;
            set;
        }
    }
This is the LoginView
<UserControl x:Class="EMDEPOS.Modern.Login.LoginView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:modern="clr-namespace:EMDEPOS.Modern"
             xmlns:cnvrter ="clr-namespace:EMDEPOS.Modern.Converters"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:command="http://www.galasoft.ch/mvvmlight"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="400"
             DataContext="{Binding Login, Source={StaticResource Locator}}">
<UserControl.Resources>
        <ResourceDictionary>
            <Style x:Key="ValiationStyle" TargetType="{x:Type Control}">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Border BorderThickness="1" BorderBrush="Red" VerticalAlignment="Top">
                                <Grid>
                                    <AdornedElementPlaceholder x:Name="adorner" Margin="-1"/>
                                </Grid>
                            </Border>
                            <Border x:Name="errorBorder" Background="Red" Margin="8,0,0,0" CornerRadius="0"
                            IsHitTestVisible="False">
                                <TextBlock Text="{Binding Path=ErrorContent}" 
                                Foreground="White" FontFamily="Segoe UI" Margin="8,2,8,3" TextWrapping="Wrap" VerticalAlignment="Center"/>
                            </Border>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
            <cnvrter:MultiBoolToVisibilityConverter x:Key="MultiBoolToVisibilityConverter"></cnvrter:MultiBoolToVisibilityConverter>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Style="{StaticResource ContentRoot}">
        <Canvas Margin="70,70,70,70" Width="200" Height="200" 
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
            <Label Content="Kullanıcı Adı:" Width="181" HorizontalAlignment="Center" 
                   VerticalAlignment="Center" Canvas.Left="9"/>
            <TextBox x:Name="txtNickName" 
                     Text="{Binding NickName, Mode=TwoWay, ValidatesOnDataErrors=True}"
                     Height="23" TextWrapping="Wrap" Canvas.Top="16" Width="180"
                     HorizontalAlignment="Center" VerticalAlignment="Center" 
                     Canvas.Left="10"
                    Style="{StaticResource ValiationStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="TextChanged">
                        <command:EventToCommand Command="{Binding DoValidateCommand, Mode=TwoWay}"></command:EventToCommand>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </TextBox>
            <Label Content="Şifre:" Canvas.Top="39" HorizontalAlignment="Center"
                   VerticalAlignment="Center" Canvas.Left="9" Width="181"/>
            <PasswordBox x:Name="txtPassword" modern:PasswordHelper.Attach ="True"
                         modern:PasswordHelper.Password="{Binding Password, Mode=TwoWay, ValidatesOnDataErrors=True}"
                         Canvas.Top="55" Width="180" HorizontalAlignment="Center" 
                         VerticalAlignment="Center" Canvas.Left="10" Height="22"
                         Style="{StaticResource ValiationStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="PasswordChanged">
                        <command:EventToCommand Command="{Binding DoValidateCommand, Mode=TwoWay}"></command:EventToCommand>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </PasswordBox>
            <Button Content="Giriş" Command="{Binding LoginCommand}" HorizontalAlignment="Left" 
                    VerticalAlignment="Top" Width="75" Canvas.Left="115" Canvas.Top="82">
                <Button.IsEnabled>
                    <MultiBinding Converter="{StaticResource MultiBoolToVisibilityConverter }">
                        <Binding ElementName="txtNickName" Path="(Validation.HasError)"></Binding>
                        <Binding ElementName="txtPassword" Path="(Validation.HasError)"></Binding>
                    </MultiBinding>
                </Button.IsEnabled>
            </Button>
        </Canvas>
    </Grid>
</UserControl>