开发者

How to pass to the Converter Parameter something that is not hard coded

Something like:

 <TextBlock Text="{Binding Text,Converter={StaticResource
  ccc},ConverterParameter=PersonName}"/>

when Person name is Prope开发者_JAVA技巧rty 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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜