问题
Something like:
<TextBlock Text="{Binding Text,Converter={StaticResource
ccc},ConverterParameter=PersonName}"/>
when Person name is Property of the class for example.
Update:
I've seen a solution that tells to inherit from DependencyObject and to implement IValueConverter. I want to know if there is something simpler.
回答1:
The answer is straight-forward, but not what you want to hear.
You can only target a binding at DependencyProperty on a DependencyObject. Binding does not inherit from DO, so you can't binding the converter parameter.
If you want other state passed into a converter, you may have to subclass the desired obect and add new properties
回答2:
Have you looked into MultiBinding? If you want two properties sent to the converter, like "Text" and "PersonName" you may be able to do something like this:
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ccc}">
<Binding Path="Text"/>
<Binding Path="PersonName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
This assumes that "Text" and "PersonNames" are properties on the DataContext. You may need to change the binding paths if that's not the case.
来源:https://stackoverflow.com/questions/6358094/how-to-pass-to-the-converter-parameter-something-that-is-not-hard-coded