Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Pass IValueConverter Parameter?

Tags:

wpf

xaml

In XAML, <Grid x:Name="MainGrid3">, Here I want to pass MainGrid3 as a parameter of IValueConverter. How can I do this?enter image description here

like image 617
MVK Avatar asked May 26 '16 11:05

MVK


1 Answers

You have ConverterParameter inside your binding, where you can use another binding with ElementName of your grid.

<Grid Name="MainGrid3"></Grid>
<TextBlock Text="{Binding SomeBinding, Converter={StaticResource SomeConverter}, 
           ConverterParameter={Binding ElementName=MainGrid3}}"></TextBlock>

Edit: Ok, so apparently I was wrong, you can't use bindings inside ConverterParameter as it is not a dependency property. Working solution would be to use x:Reference like so:

<Grid Name="MainGrid3"></Grid>
<TextBlock Text="{Binding SomeBinding, Converter={StaticResource SomeConverter}, 
           ConverterParameter={x:Reference Name=MainGrid3}}"></TextBlock>
like image 145
Matas Avatar answered Oct 14 '22 12:10

Matas