How to set image source in Panorama Control in Windows Phone 7 code behind?

570 views Asked by At

I am trying to create a simple Panorama application, which is really similar to the default code when you choose to create a Panorama application in Visual Studio.

What I want is, I define my own ItemViewModel with an extra icon image field, so the new model has 4 properties: Icon, LineOne, LineTwo and LineThree. Icon is an image or an string of path of the image file, LineOne, LineTwo and LineThree are string type.

The default code has something like:

this.Items.Add(new ItemViewModel() { 
    LineOne = "runtime one", 
    LineTwo = "Maecenas praesent accumsan bibendum",
    LineThree = "Facilisi faucibus habitant inceptos interdum lobortis nascetur pharetra placerat pulvinar sagittis senectus sociosqu" 
});

In the LoadData method of MainViewModel.cs class, I am wondering if I can have something like that, but I can specify which icon image I want to set in this method? e.g.:

this.Items.Add(new NewItemViewModel() { Icon = new Image().Source == "/Images/lineone.jpg" , LineOne = "lineone", LineTwo = "linetwo", LineThree = "linethree" });

Thank you.

1

There are 1 answers

4
Ku6opr On

Make your Icon property as string and bind it to Source of Image control in xaml

 <Image ImageSource={Binding Icon} ... />

That you can setup your image like that (don't forget to set type of image as Content)

 this.Items.Add(new NewItemViewModel() { Icon = "/Images/lineone.jpg" , LineOne = "lineone", LineTwo = "linetwo", LineThree = "linethree" })