MarcinJuraszek
MarcinJuraszek

Reputation: 125650

Panorama Title binding

I'm doing WP7 app using Panorama control and have a problem with binding into Panorama Title property. Is it possible to bind that value out from ViewModel object?

Binding in xaml file:

<controls:Panorama x:Name="prmPanorama" Title="{Binding Voyage.Title}">

Voyage property of ViewModel is a Model entity (with Title property inside) with OnNotifyPropertyChanged event fired every time it changes:

private Voyage _voyage;
public Voyage Voyage
{
    get { return _voyage; }
    set
    {
        if (_voyage != value)
        {
            _voyage = value;
            OnNotifyPropertyChanged("Voyage");
        }
    }
}

When I bind the same property into another control, eg. TextBlock, binding works just fine:

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

The text shown in that text block is as it should be but on the same time panorama title is not binded right - it's collapsed.

Does anyone tried to do that kind of binding? I have no idea why it doesn't work.

Upvotes: 3

Views: 890

Answers (1)

Edward
Edward

Reputation: 7424

    <DataTemplate x:Key="TitleDataTemplate"> 
       <TextBlock Text="{Binding}" /> 
    </DataTemplate>
    ... 
    <controls:Panorama Title="{Binding Voyage.Title}" 
                       TitleTemplate="{StaticResource TitleDataTemplate}">

The control template of the panorama control uses a content presenter to display whatever value the its title property has kind of like a button. When setting the title template property, you indirectly set the content template of the content presenter.

That is why you have to set the title property on the panorama control and then can use that value in your title template for binding. In other words its not enough to just bind to the title you have to give it a template.

Check out this link for more info

Upvotes: 1

Related Questions