Skip to main content

Microsoft Silverlight

Answered Question Display Image dynamicallyRSS Feed

(0)

Rajeev BV
Rajeev BV

Member

Member

17 points

38 Posts

Display Image dynamically

Is it possible to display images in a silverlight application say from an adpater class or an external dll? This class / dll would actually provide the images, which Silverlight would convert into bmp/ jpeg or something & then display

lingbing
lingbing

Contributor

Contributor

2249 points

406 Posts

Re: Display Image dynamically

Hi, I think just Binding the image control's Source to the string of uri is ok, it is like:

<Grid x:Name="MyGrid">
<Image Source="{Binding URL"}/>
</Grid>

 and in you code behind, create a simple data class like:
public class Data:INotifyPropertyChanged
{
            private string m_URL;
            public string URL
            {
                   get{  return m_URL; }
                   set
                   {
                        m_URL=value;
                        OnPropertyChanged("URL");
                   }
            }
            #region INotifyPropertyChanged Members

            public event PropertyChangedEventHandler PropertyChanged;
            protected virtual void OnPropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }

            #endregion
}

then, if your code-behind,
Data data=new Data();
data.URL="http://xxxxx.com/xxx.png";//or "images/xxx.png";
MyGrid.DataContext= data;

DataBinding will help you set the image source, and because the INotifyPropertyChanged interface, when you change data.URL property, the image's source will change too.

Hope it help! Regards.

Ling Bing
Bei Jing University of Aeronautics and Astronautics
Bei Jing, China

Rajeev BV
Rajeev BV

Member

Member

17 points

38 Posts

Re: Display Image dynamically

Thanks for the reply. But is it possible that the class itself returns an image & can that be bound in Silverlight application?

 

moemeka
moemeka

Member

Member

147 points

69 Posts

Answered Question

Re: Display Image dynamically

Hi,

  yes there are lots of ways you can achieve this.  silverlight can load images, files, zipz, silverlight libraries, and even other sl applications dynamically.   On approach would be,

1) bind class to a page's datacontext (this.datacontext = <some_dynamic_image_class_instance>)

2) bind some image within the page to an appropriate property of the datacontext class

3) use whatever mechanism withing your dynamic image class to change the actual image returned by the property as needed.

every change will result in the picture changing on the page.  from the standpoint of your page, it will not need to know where the image is comming from, just that this class provides it with images through it's 'image' property.

 

Hope this helps.

 

Please mark as answered if this post resolves your issue.

http://moemeka.blogspot.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities