-1

I want to make a user control that contains Image control and I want to bind its source with a url of image. How to do this in the user control XAMl and CS code and how to use this user control and bind its dependency property ?

Abdullah El-Menawy
  • 388
  • 1
  • 5
  • 17

2 Answers2

0

You could have the Image control like this, which you could bind the source to it:

<Image Width="75" Height="75" Source="{Binding thumbUrl}" Stretch="Fill"/>

For more you could refer these:

Image databinding XAML, Silverlight, C#, Windows Phone 7.1

http://www.geekchamp.com/tips/data-binding-images-in-windows-phone

Hope it helps!

Community
  • 1
  • 1
Kulasangar
  • 9,046
  • 5
  • 51
  • 82
0

You can create a user control by,

(i)Right click the project tile in Solution Explorer and then select Add->New Item

(ii)Select Windows Phone User Control from the pop up windows, set the name that you want to use

(iii)Add the following code inside the XAML part of the user control

<StackPanel x:Name="LayoutRoot" >
    <TextBlock Text="My User Control" FontSize="34"/>
     <Image x:Name="Image1" Source="{Binding ImageUrl}" />
</StackPanel>

Define a property in your Model,

public Uri ImageUrl { get; set; }

and bind it to your Image

Uri uri = new Uri("http://Abundantcode.com/image.jpg", UriKind.Absolute)
Image1.Source = new BitmapImage(uri);

Now you can use UserControl anywhere you want,

<local:MyUserControl x:Name="myUserControl" />
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396