You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library allows to create `IValueConverter` and `IMultiValueConverter` objects with the most convenient syntax available, ideally, using the lambda expressions.
3
+
The library allows to create `IValueConverter`, `IMultiValueConverter`, `DataTemplateSelector`, and `ValidationRule` objects with the most convenient syntax available, ideally, using the lambda expressions.
4
+
5
+
## Lambda Value Converters
4
6
5
7
First create a (static) class and define your converters as static fields (or properties):
6
8
@@ -26,43 +28,37 @@ You're done! Just reference the converters with the `x:Static` expressions from
- resource declaration not needed, just use the `x:Static` expressions
32
34
- separate class for each converter not needed anymore
33
35
- no redundant declarations: if you do not need the `ConvertBack` method, don't define it; otherwise, just put the second lambda expression
34
36
- full support for the remaining parameters of the `Convert` and `ConvertBack` methods: the `culture` and the `parameter` (also strongly-typed) are accessible as well
35
37
- if the conversion fails due to unexpected value types the optional [error strategy](Sources/LambdaConverters.Wpf/ConverterErrorStrategy.cs) can be specified
36
38
37
-
:bulb:*ReSharper users*: use the Extension Manager to install the external annotations for the library.
38
-
39
-
## Lambda DataTemplateSelectors
39
+
## Lambda Data Template Selectors
40
40
41
-
The library also allows to create `DataTemplateSelector` objects in the same convenient way as Converters. In order to define a Selector simply write a static field (or property) similar to this snippet:
41
+
The library also allows to create `DataTemplateSelector` objects in the same convenient way as value converters. In order to define a selector simply write a static field (or property) similar to this snippet:
Use your Lambda DataTemplateSelectors by referencing it with the `x:Static` markup extention:
53
+
Use your Lambda DataTemplateSelectors by referencing it with the `x:Static` markup extention (assuming that `s` is the namespace definition for the `TemplateSelector` class):
@@ -80,7 +76,7 @@ Tada! All even numbers from `IntNumbers` are displayed with black font and white
80
76
- separate class for each selector not needed anymore
81
77
- full support for the remaining parameter `container`. For example, if you need to grab a `DataTemplate` from where the selector is use (see the example above).
82
78
83
-
## Lambda ValidationRules
79
+
## Lambda Validation Rules
84
80
85
81
Furthermore, you'll get Lambda ValidationRules on top. By now you know "the drill". First, define a `ValidationRule`object like this:
86
82
@@ -89,12 +85,12 @@ public static class Rule
89
85
{
90
86
publicstaticValidationRuleIsNumericString=
91
87
LambdaConverters.Validator.Create<string>(
92
-
e=>e.Value.ToCharArray().All(char.IsDigit)
93
-
?ValidationResult.ValidResult
94
-
:newValidationResult(false, "Text has non-digit characters!"));
88
+
e=>e.Value.All(char.IsDigit)
89
+
?ValidationResult.ValidResult
90
+
:newValidationResult(false, "Text has non-digit characters!"));
95
91
}
96
92
```
97
-
And then reference your new rule in vour `View`:
93
+
And then reference your new rule in vour `View` (assuming that `r` is the namespace definition for the `Rule` class):
98
94
```xml
99
95
<TextBox>
100
96
<TextBox.Text>
@@ -117,6 +113,8 @@ Now, you made sure that only strings which consists of digits are passed to your
117
113
## Installation
118
114
Use the NuGet package manager to install the package.
119
115
116
+
:bulb:*ReSharper users*: use the Extension Manager to install the external annotations for the library.
0 commit comments