Multi value converter xaml
In your particular case, all you need to do is format a converted value to a string. StringFormat property on a Binding is your friend here. Here is a small extension of Town's answer to support multi-binding:. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Is there a way to chain multiple value converters in XAML? Ask Question. Asked 11 years, 9 months ago. Active 2 years, 3 months ago. Viewed 50k times.
I've got a situation in which I need to show an integer value, bound to a property on my data context, after putting it through two separate conversions: Reverse the value within a range e. If I need to clarify any of this, please let me know.
Improve this question. Mal Ross Mal Ross 4, 4 4 gold badges 32 32 silver badges 46 46 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Town Town Is it best, for an implementation of ConvertBack to make a copy of the collection and reverse it, and then Aggregate over that? So the ConvertBack would be return this. ConvertBack current, targetType, parameter, culture ; — Nick Udell. DLeh This is not really elegant as is doesn't work.
In this case the convert back function of IMultiValueConverter interface must be usde. In the following code example of the fullnameconverter class I have used both the convert and convert back functions to do it. The convert function in the preceding code concatenates the two data items coming from the two sources with a space between them and returns the concatenated data to the target. The convert back function splits the concatenated string with a space to an array of strings and returns the items of the array to the corresponding source.
In the preceding scenario the convert back function takes the text of both the first name TextBox and the last name TextBox and concatenates the text with a space between the two texts and returns that to the third TextBox.
Again, when you fill in the data in the third TextBox, the convert back function takes the text and splits it into an array string using a space and returns that to the source textboxes first name TextBox and last name TextBox. To use a converter you need to implement the interface of the converter class in the XAML page of WPF, you need to declare the resource. After declaring the resource it is necessary to use it with binding.
See the following XAML code example. Yes, there are ways to chain converters but it does not look pretty and you don't need it here. If you ever come to need this, ask yourself is that really the way to go?
Simple always works better even if you have to write your own converter. In your particular case, all you need to do is format a converted value to a string. StringFormat property on a Binding is your friend here. Here is a small extension of Town's answer to support multi-binding:.
0コメント