-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
100 lines (85 loc) · 3.23 KB
/
MainWindow.xaml.cs
File metadata and controls
100 lines (85 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DevExpress.Xpf.Editors;
using System.ComponentModel;
namespace WpfApplication147 {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
}
public class TestClass : IDataErrorInfo, INotifyPropertyChanged {
string testString;
public string TestString {
get { return testString; }
set {
testString = value;
RaisePropertyChanged("TestString");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
void RaisePropertyChanged(string property) {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
#endregion
#region IDataErrorInfo Members
string IDataErrorInfo.Error {
get { return GetError(); }
}
string GetError() {
if (string.IsNullOrEmpty(TestString))
return "ErrorType=Critical;ErrorContent=The value is not provided. Please enter a value";
if (TestString.Length < 3)
return "ErrorType=Warning;ErrorContent=The value is less than 3 characters. Please enter at least 5 characters";
if (TestString.Length < 5)
return "ErrorType=Information;ErrorContent=The value is less than 5 characters. Please enter at least 5 characters";
return string.Empty;
}
string IDataErrorInfo.this[string columnName] {
get {
if (columnName == "TestString")
return GetError();
return string.Empty;
}
}
#endregion
}
public class ErrorContentConverter : IValueConverter {
public string GetValueTag { get; set; }
public string Separator { get; set; }
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
if (value == null || !(value is string))
return value;
string error = System.Convert.ToString(value, culture);
if (string.IsNullOrEmpty(error))
return value;
string searchString = GetValueTag + "=";
foreach (string suberror in error.Split(new string[] { Separator }, StringSplitOptions.RemoveEmptyEntries)) {
if (suberror.Contains(searchString))
return suberror.Replace(searchString, string.Empty);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
return null;
}
#endregion
}
}