Binding is one of the most powerful features introduced in WPF, it allows us to implement complex data-based UI, using minimum of declarative code (XAML), while relying on a ‘built-in‘, out of the box mechanism that connects data to UI-controls in a direct way or through Converters.
Binding converters are by nature an encapsulated functions that receive the
bound value, manipulate it in a specific manner, and return the manipulated
result. On many occasions another source of information is needed for the
converter in order to ‘do its job‘, this source is called
‘ConverterParameter
‘ and it‘s one of the
converter‘s Convert
and ConvertBack
method
parameters.
WPF‘s out-of-the-box Bindings restricts
the ConverterParameter
to receive (from XAML) only Static
or Resource values, while passing it a Binding expression is forbidden:
// // this line of xaml produce the following error: // <TextBox Text="{Binding Path=FirstName,Converter={StaticResource TestValueConverter},ConverterParameter={Binding Path=ConcatSign}}" />
In many cases this feature (Bindable ConverterParameter
) is
exactly what ones need. I.e.,
the ConverterParameter
value which is a
Binding-Expression (rather than a static predefined value) will be evaluated
each time the binding evaluation is triggered, and will passed to the Converter
as the ConverterParameter
parameter.
In this article I‘ll show a relatively simple and straightforward technique
to achieve just that. The XAML part that will implement the
bound ConverterParameter
will look as close as possible
to the Error producing line of code above, with the exception that it will
work...
相关连接
Bindable Converter Parameter,布布扣,bubuko.com
原文:http://www.cnblogs.com/xszlo/p/3683186.html