Sapp
Sapp

Reputation: 1

Bind multiple values to a textblock

I bind a appointment object to a 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?

Upvotes: 0

Views: 443

Answers (2)

Depechie
Depechie

Reputation: 6142

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/

It allows to give multiple input params for one output. The toolkit can be installed through NuGet

Upvotes: 0

JustMeToo
JustMeToo

Reputation: 425

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. Just search on "C# ValueConverter" to get info on how to use it.

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.

Upvotes: 1

Related Questions