AvaloniaUI / Avalonia.Samples

Avalonia.Samples aims to provide some minimal samples focusing on a particular issue at a time. This should help getting new users started.
https://www.avaloniaui.net
606 stars 103 forks source link

Add FuncValueConveter Sample #71

Closed timunie closed 8 months ago

timunie commented 8 months ago

What does the pull request do?

Adds a missing sample about FuncValueConverter usage

Scope of this PR:

What is the current behavior?

Only IValueConverter and IMultiValtueConverter was covered

Checklist

If this is a new Sample

In any case

Fixed issues

Fixes #51

timunie commented 8 months ago

FuncValueConverter is yet missing from the docs. Will add it once this is merged.

draft:

## FuncValueConverter

You can also implement a `FuncValueConverter` if you don't need to convert back and also not the the `ConverterParameter`. The FuncValueConverter has two generic parameters:

**TIn**: This parameter defines the expected input type. This can also be an array in case you want to use this converter in a MultiBinding.

**TOut**: This parameter defines the expected output type.

### Example:
```cs
public static FuncValueConverter<string, string> MyConverter { get; } = new FuncValueConverter<string, string>(s => $"You said '{s}');
<!-- TODO -->