How to data bind multiple values to a single TextBlock.Text in WP7?
Asked Answered
C

2

9

How can I bind 2 properties to a single TextBlock.Text (eg. first name and last name or current value and max value)?

something like:

// IValueConverter
public object Convert( .... )
{
    return string.Format("{0} (max: {1})", currentValue, maxValue);
}

The problem is I want TextBlock.Text to be updated when currentValue or maxValue has changed. So how can I listen to changes from 2 or more properties using data binding?

Is there another way than usering IValueConverter?

Clarkson answered 11/2, 2011 at 10:52 Comment(0)
S
9

Silverlight 3 (on which the Windows Phone 7 framework is built) doesn't support MultiBinding, which is what you would use to achieve what you need. However, there is a workaround solution that you can use described in the post MultiBinding for Sivlerlight 3, which should also work on WP7.

Alternatively, you could extend your view model (or at least the properties that you are exposing) to expose a property that aggregates your values and raises property change notification when either changes.

Storyteller answered 11/2, 2011 at 11:2 Comment(1)
thanks for the answer. I did came to the same conclusion. I hoped there would be another solution for this.Clarkson
P
2

If you are working with WP7.1 (I know you mentioned WP7), take a look at the Cimbalino Windows Phone Toolkit. It offers a MultiBindingBehavior.

Provided answered 1/3, 2014 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.