2
votes

I am developing a Windows Store App which displays fields of specific types throughout the App and allows the user to change their preference of units for display of that type of field.

Using an example of fields related to Heights, if using MultiBinding from WPF (not available in WinRT) I would want to do something like this:

<Page x:Name="Page" ...>

...

    <TextBlock>
        <TextBlock.Text>
            <MultiBinding Converter={StaticResource HeightConverter}>
                <Binding Path="HeightInMetres"/>
                <Binding Path="HeightDisplayUnit" ElementName="Page"/>
            </MultiBinding>
        </TextBlock.Text>

    </TextBlock>

....

</Page>

Where HeightUnit would be an enumeration for say feet, metres..

The HeightDisplayUnit and HeightInMetres are held in separate view-models.

In the example above the HeightDisplayUnit is a property of a the Page class and the HeightInMetres being a property of a view-model of type Person which is bound throughout including for example in DataTemplates used in ListViews. There is a single instance of the view-model containing HeightDisplayUnit but many instances of the Person view-model.

In various spots in the App I may have binding to person where I want to use the Can anyone think of a way to achieve the aim of triggering an update to all the "height" fields when either the Page property HeightDisplayUnit or the HeightInMetres property of the Person view-model is updated.

4

4 Answers

2
votes

It's straightforward to add another read-only property in the view-model. Just remember to raise "PropertyChanged" from each of the other properties.

<TextBlock Text="{Binding FormattedHeight}" />

...

public string FormattedHeight
{
    get { return string.Format("{0} {1}", HeightInMetres, HeightDisplayUnit); }
}
2
votes

Considering that the data your are binding are coming from different view models and it could be too complicated to merge them into a single property, you should consider creating a custom control to handle this scenario.

While you will still not be able to multi-bind, you will be able to expose two DependencyProperties to handle the bindings.

2
votes

There are NuGet packages that provide MultiBinding functionality for Windows Store apps. You can find documentation here.

1
votes

you could add multiple Runs to 1 textblock and bind both of them to different sources:

<Page.Resources>
    <x:String x:Key="String1">AAA</x:String>
    <x:String x:Key="String2">BBB</x:String>
</Page.Resources>

<Grid>
    <TextBlock>
        <Run Text="{StaticResource String1}"></Run>
        <Run Text="{StaticResource String2}"></Run>
    </TextBlock>
</Grid>