xcopy
xcopy

Reputation: 2288

Data binding image to Panorama Control in WP7 not working

Can anyone shed some light as to why the following code is not working? By "not working" I mean the image is not rendered in the Panorama control:

XAML

DataContext="{Binding RelativeSource={RelativeSource Self}}"
shell:SystemTray.IsVisible="False">

<Grid x:Name="LayoutRoot">
    <controls:Panorama Title="My Control">
        <controls:Panorama.Background>
            <ImageBrush ImageSource="{Binding RandomImage}"/>
        </controls:Panorama.Background>

C#

public string RandomImage { get; set; }

Note: The RandomImage property is set to a public jpg image on the internet.

EDIT

I have also tried to change the RandomImage property to ImageSource but did not have any luck with that.

Upvotes: 1

Views: 1149

Answers (1)

Zann Anderson
Zann Anderson

Reputation: 4897

I'm gonna hazard a guess that you're setting RandomImage at some point after the page loads, which means that the binding has already been checked. You need to implement INotifyPropertyChanged and call your PropertyChanged event in the setter for RandomImage. For a detailed explanation of this, check out this MSDN article.

The long and short of it is that the binding is checked when the page loads and then not again unless something triggers it. Implementing INotifyPropertyChanged means that when you call your PropertyChanged event, it notifies the UI to check the binding again and see what's new so it can update itself.

Upvotes: 1

Related Questions