Как выполнить проверку в richtextbox с использованием интерфейса IDataerroInfo? - PullRequest
0 голосов
/ 26 июня 2019

Я пытаюсь реализовать интерфейс Idataerrorinfo на richtextbox для пользовательской проверки.Я успешно реализовал его для текстового поля, когда следовал тому же шаблону для реализации richtextbox, но ничего не происходит вокруг richtextbox.

windows.xaml:

 <Window.Resources>
        <ControlTemplate x:Key="ErrorTemplate">
            <DockPanel LastChildFill="True">
                <Border BorderBrush="Red" BorderThickness="1">
                    <AdornedElementPlaceholder />
                </Border>
            </DockPanel>
        </ControlTemplate>
  <Style TargetType="TextBox">

            <Style.Triggers>

                <Trigger Property="Validation.HasError" Value="true">

                    <Setter Property="ToolTip"

          Value="{Binding RelativeSource={x:Static RelativeSource.Self},

Path=(Validation.Errors)[0].ErrorContent}"/>

                </Trigger>

            </Style.Triggers>

        </Style>

   <Style TargetType="RichTextBox">

            <Style.Triggers>

                <Trigger Property="Validation.HasError" Value="true">

                    <Setter Property="ToolTip"

          Value="{Binding RelativeSource={x:Static RelativeSource.Self},

Path=(Validation.Errors)[0].ErrorContent}"/>

                </Trigger>

            </Style.Triggers>

        </Style>

    </Window.Resources>


                        <TextBlock Grid.Column="0" Text="Comments" HorizontalAlignment="Center"  VerticalAlignment="Center" Width="70" />



<RichTextBox Grid.Column="1">
         <FlowDocument PageHeight="180">
               <Paragraph>
                   <Run Text="{Binding informationdata.Usercomments, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"  Validation.ErrorTemplate="{StaticResource ErrorTemplate}"/>
                     </Paragraph>
                     </FlowDocument>
                      </RichTextBox>

 <TextBlock Grid.Column="5" Text="Time Taken" HorizontalAlignment="Center"  VerticalAlignment="Center" Width="79" />


 <TextBox Grid.Column="6" IsEnabled="{Binding informationdata.Isdisabled}" HorizontalAlignment="Center" VerticalAlignment="Center"  Width="99" Height="19" Text="{Binding informationdata.Timetaken, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"   Validation.ErrorTemplate="{StaticResource ErrorTemplate}"/>

Viewmodel.cs:

   private string GetValidationError(string propertyName)
    {
        string errorMsg = null;

        switch (propertyName)
        {

            case "Timetaken":
                if ((propertyName.Equals("Timetaken")))
                {
                    if (String.IsNullOrEmpty(this.Timetaken))

                        errorMsg = "Please provide the TimeTaken";
                    else if (CheckInteger(Timetaken) == false)
                        errorMsg = "The given TimeTaken is not a Number";
                    else if (Timetaken.Length > 480)
                        errorMsg = "The TimeTaken in mins should be less than 480 Mins";

                }

                break;

            case "Usercomments":
                if ((propertyName.Equals("Usercomments")))
                {
                    if (String.IsNullOrEmpty(this.Usercomments))

                        errorMsg = "Please provide the User comments";


                }

                break;

        }
        return errorMsg;
    }

    public string this[string columnName]

    {

        get

        {
            return GetValidationError(columnName);

        }

    }

В приведенном выше коде проверка текстового поля работает нормально, но с richtextbox ничего не происходит вокруг него, и я не уверен, как найти, что с ним не так.

...