简体   繁体   English

将多个值绑定到文本块

[英]Bind multiple values to a textblock

I bind a appointment object to a Textblock: 我将约会对象绑定到Textblock:

TextBlock textBlock = new TextBlock();
Binding binding = new Binding();
binding.Path = new PropertyPath("Subject");
textBlock.SetBinding(TextBlock.TextProperty, binding);
textBlock.DataContext = appointment;

The result is, that the Subject of the appointment is shown in the Textblock. 结果是,约会的主题显示在文本块中。

Now I want that the time of the appointment is shown in the textblock before the subject of the appointment. 现在,我希望在约会主题之前的文本框中显示约会的时间。 Can anybody help me modifying my source code to get that result? 有人可以帮助我修改源代码以获得该结果吗?

I am probably missing something obvious, but couldn't you use one of the following: 我可能缺少明显的东西,但是您不能使用以下之一:

  • create a property that combines the values (from other properties) and can parse out changes back to those source properties. 创建一个组合值(来自其他属性)的属性,并可以将更改解析回这些源属性。 Then bind to that instead. 然后绑定到那个。
  • use a ValueConverter and bind to that. 使用ValueConverter并将其绑定。 Just search on "C# ValueConverter" to get info on how to use it. 只需搜索“ C#ValueConverter”即可获取有关如何使用它的信息。

There are probably a few others, but those come to mind on first thought. 可能还有其他一些,但是首先想到的就是这些。 If neither of these will work for you, let us know. 如果这些都不适合您,请告诉我们。

Well there is always the MultiBindingBehaviour from the Cimbalino toolkit, it's explained here https://www.pedrolamas.com/2013/05/17/cimbalino-windows-phone-toolkit-multibindingbehavior/ 好吧,总是有Cimbalino工具包提供的MultiBindingBehaviour,在这里进行了说明https://www.pedrolamas.com/2013/05/17/cimbalino-windows-phone-toolkit-multibindingbehavior/

It allows to give multiple input params for one output. 它允许为一个输出提供多个输入参数。 The toolkit can be installed through NuGet 该工具包可以通过NuGet安装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM