Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference current object in XAML

Tags:

.net

wpf

xaml

I cant' figure out how to reference the current instance object defined by the XAML file in the XAML file.

I have a converter that I want to send in the current instance as the parameter object.

{Binding Path=<bindingObject>, Converter={x:Static namespace:Converter.Instance}, ConverterParameter=this}

In this code this is converted to a string instead of a reference to the current instance object.

Thanks

John

like image 999
user9331 Avatar asked Oct 23 '08 20:10

user9331


2 Answers

According to the Data Binding Overview, you can use the "/" to indicate the current item. You can then navigate up and down the tree as needs be using the following type syntaxes:

<Button Content="{Binding }" />
<Button Content="{Binding Path=/}" />
<Button Content="{Binding Path=/Description}" /> 
like image 55
Dillie-O Avatar answered Oct 26 '22 00:10

Dillie-O


Technically, the ConverterParameter is not a DependencyProperty, so you can't bind to it. It would be nice to do a ConverterParameter={Binding ElementName=this}, but you can't bind to a non-dependency property.

But, someone figure it out how to do it here. This is however a bit complicated.

like image 38
decasteljau Avatar answered Oct 26 '22 01:10

decasteljau