Dan
Dan

Reputation: 13343

XAML - Binding to DataContext and using converter?

To bind to the current DataContext in XAML you can use:

<TextBlock Text="{Binding}" />

How do you do this using a converter in the mix? The following works when you have a property on the path:

<TextBlock Text="{Binding MyProperty,Converter={StaticResource converter}}" /> 

But I dont want to do that; I just want to Bind to the datacontext and not the datacontext.MyProperty if you get what I mean.

Upvotes: 17

Views: 8903

Answers (2)

Davut G&#252;rb&#252;z
Davut G&#252;rb&#252;z

Reputation: 5716

Dot sign also provide DataContext Binding for SL developers

<TextBlock Text="{Binding Path=.,Converter={StaticResource converter}}" />

Upvotes: 1

Matt Hamilton
Matt Hamilton

Reputation: 204139

Simply omit the path:

<TextBlock Text="{Binding Converter={StaticResource converter}}" />

Ah wait - I notice your question is tagged with Silverlight. Does this not work in Silverlight? If not, you may need to use the expanded syntax:

<TextBlock>
    <TextBlock.Text>
        <Binding Converter="{StaticResource converter}" />
    </TextBlock.Text>
</TextBlock>

Upvotes: 34

Related Questions