WPF绑定:其中属性包含值的路径 [英] WPF Binding: Where a property contains the path to the value

查看:52
本文介绍了WPF绑定:其中属性包含值的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在顶部栏中有一个带有两个TextBlocks的扩展器,我正在使用它来提供标题和一些关键信息.

I've got an expander with a couple of TextBlocks in the top bar which i'm using to give a title and a piece of key information.

理想情况下,我想将路径设置为关键信息,但是我无法解决如何将绑定路径绑定到另一条路径(如果我没有太大意义,我深表歉意!)

Ideally i want to set the path to key piece of information, but i can't work out how to bind the path of the binding to another path (i apologise if i'm not making much sense!)

在下面的xaml中,第一位有效,第二位是我正在努力的目标.

In the following xaml the first bit works, the second bit is what i'm struggling with.

<TextBlock Text="{Binding Path=Header.Title}"/>

<TextBlock Text="{Binding Path={Binding Path=Header.KeyValuePath}}"/>

根据模型,KeyValuePath可能包含"Vehicle.Registration"或"Supplier.Name"之类的内容.

KeyValuePath might contain something like "Vehicle.Registration" or "Supplier.Name" depending on the Model.

有人可以指出我的正确方向吗?感谢您的任何帮助!

Can anyone point me in the right direction please? Any help gratefully received!

推荐答案

我不认为可以在纯XAML中完成...路径不是DependencyProperty(而且无论如何绑定都不是DependencyObject),因此它可以不是绑定的目标

I don't think it can be done in pure XAML... Path is not a DependencyProperty (and anyway Binding is not a DependencyObject), so it can't be the target of a binding

您可以改为在代码后面修改绑定

You could modify the binding in code-behind instead

这篇关于WPF绑定:其中属性包含值的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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