Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. <Window.Resources>
  2. <ControlTemplate x:Key="ErrorTemplate">
  3. <DockPanel LastChildFill="True">
  4. <Border BorderBrush="Red" BorderThickness="1">
  5. <AdornedElementPlaceholder />
  6. </Border>
  7. </DockPanel>
  8. </ControlTemplate>
  9. <Style TargetType="TextBox">
  10.  
  11. <Style.Triggers>
  12.  
  13. <Trigger Property="Validation.HasError" Value="true">
  14.  
  15. <Setter Property="ToolTip"
  16.  
  17. Value="{Binding RelativeSource={x:Static RelativeSource.Self},
  18.  
  19. Path=(Validation.Errors)[0].ErrorContent}"/>
  20.  
  21. </Trigger>
  22.  
  23. </Style.Triggers>
  24.  
  25. </Style>
  26.  
  27. <Style TargetType="RichTextBox">
  28.  
  29. <Style.Triggers>
  30.  
  31. <Trigger Property="Validation.HasError" Value="true">
  32.  
  33. <Setter Property="ToolTip"
  34.  
  35. Value="{Binding RelativeSource={x:Static RelativeSource.Self},
  36.  
  37. Path=(Validation.Errors)[0].ErrorContent}"/>
  38.  
  39. </Trigger>
  40.  
  41. </Style.Triggers>
  42.  
  43. </Style>
  44.  
  45. </Window.Resources>
  46.  
  47.  
  48. <TextBlock Grid.Column="0" Text="Comments" HorizontalAlignment="Center" VerticalAlignment="Center" Width="70" />
  49.  
  50.  
  51.  
  52. <RichTextBox Grid.Column="1">
  53. <FlowDocument PageHeight="180">
  54. <Paragraph>
  55. <Run Text="{Binding informationdata.Usercomments, Mode=TwoWay, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"/>
  56. </Paragraph>
  57. </FlowDocument>
  58. </RichTextBox>
  59.  
  60. <TextBlock Grid.Column="5" Text="Time Taken" HorizontalAlignment="Center" VerticalAlignment="Center" Width="79" />
  61.  
  62.  
  63. <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}"/>
  64.  
  65. private string GetValidationError(string propertyName)
  66. {
  67. string errorMsg = null;
  68.  
  69. switch (propertyName)
  70. {
  71.  
  72. case "Timetaken":
  73. if ((propertyName.Equals("Timetaken")))
  74. {
  75. if (String.IsNullOrEmpty(this.Timetaken))
  76.  
  77. errorMsg = "Please provide the TimeTaken";
  78. else if (CheckInteger(Timetaken) == false)
  79. errorMsg = "The given TimeTaken is not a Number";
  80. else if (Timetaken.Length > 480)
  81. errorMsg = "The TimeTaken in mins should be less than 480 Mins";
  82.  
  83. }
  84.  
  85. break;
  86.  
  87. case "Usercomments":
  88. if ((propertyName.Equals("Usercomments")))
  89. {
  90. if (String.IsNullOrEmpty(this.Usercomments))
  91.  
  92. errorMsg = "Please provide the User comments";
  93.  
  94.  
  95. }
  96.  
  97. break;
  98.  
  99. }
  100. return errorMsg;
  101. }
  102.  
  103. public string this[string columnName]
  104.  
  105. {
  106.  
  107. get
  108.  
  109. {
  110. return GetValidationError(columnName);
  111.  
  112. }
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement