Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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}"/>
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement