bovender framework
C# framework that implements MVVM and more
StringMessageContent.cs
1 /* StringMessageContent.cs
2  * part of Daniel's XL Toolbox NG
3  *
4  * Copyright 2014-2018 Daniel Kraus
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 using System;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using System.Linq;
22 using System.Text;
23 
24 namespace Bovender.Mvvm.Messaging
25 {
31  public class StringMessageContent : MessageContent, IDataErrorInfo
32  {
33  #region Public properties
34 
35  public string Value { get; set; }
36 
40  public Func<string, string> Validator { get; set; }
41 
42  #endregion
43 
44  #region Constructors
45 
46  public StringMessageContent() : base() { }
47 
48  public StringMessageContent(string initialValue)
49  : base()
50  {
51  Value = initialValue;
52  }
53 
54  #endregion
55 
56  #region IDataErrorInfo implementation
57 
58  string IDataErrorInfo.Error
59  {
60  get { return (this as IDataErrorInfo)["Value"]; }
61  }
62 
63  string IDataErrorInfo.this[string columnName]
64  {
65  get
66  {
67  if (columnName == "Value")
68  {
69  return Validator(Value);
70  }
71  else
72  {
73  return String.Empty;
74  }
75  }
76  }
77 
78  #endregion
79 
80  #region Overrides
81 
86  protected override bool CanConfirm()
87  {
88  return String.IsNullOrEmpty((this as IDataErrorInfo)["Value"]);
89  }
90 
91  #endregion
92  }
93 }
override bool CanConfirm()
Disables the Confirm command if the Value is invalid.
Encapsulates a string message that is part of the content that a view model sends to a consumer (view...
Simple object that encapsulates a boolean value; to be used in MVVM interaction with MessageArgs...