XAML - 绑定到的DataContext并使用转换器? [英] XAML - Binding to DataContext and using converter?

查看:144
本文介绍了XAML - 绑定到的DataContext并使用转换器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要绑定到XAML当前的DataContext你可以使用:

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}}" />

但我不想这样做;我只是想,如果你明白我的意思绑定到DataContext的,而不是datacontext.MyProperty。

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.

推荐答案

简单地忽略路径:

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

等待啊 - 我注意到你的问题是标签使用Silverlight。这难道不是在Silverlight中工作?如果没有,你可能需要使用扩展的语法:

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>

这篇关于XAML - 绑定到的DataContext并使用转换器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆