Hi,
My application is in VS2010,Silverlight and coded in C#.Net.
My requirement is i want to upload Image in my Imagebox control.As there is no PictureBox control in Silverlight im using ImageBox.
I have a Imagebox,below that a Browse button.
When the User clicks on Browse button,Dialogbox should open and when the USer selects a Image it should be loaded to Image box..
Example for Picturebox is available on the forum but i want it for Imagebox.
Below is my code.

OpenFileDialog imageDialog = new OpenFileDialog();

            //Filter default filetype to be allowed for selection 
            imageDialog.Filter = "Pictures (*.jpg)|*.jpg";
            imageDialog.FilterIndex = 1;

            //Allows multiple files to be selected 
            imageDialog.Multiselect = true;

            //Call the ShowDialog method to show the dialog box 
            bool? userClickedOK = imageDialog.ShowDialog();

            //Process input if the user clicked OK 

            if (userClickedOK == true)
            {
              image1.Source = 
            }

image1 is my image control
Please correct me in image1.Source=.....

I don't know of any ImageBox in C#.
Only a PictureBox control with an Image property.
To load an image in a picturebox use something like:
pictureBox1.Image = MyJPEGimage;

im Using Silverlight.I have tried Picturebox in normal windows application.
But there is no Picturebox in silverlight application on Imagebox is there.

imageDialog is the object of OpenFileDialog and i was assigning this object to Image Source.

We will have to bind image to Image.Source. Below is the code snippet I tried and able to bind image.

OpenFileDialog objFileDialog = new OpenFileDialog();
            bool? IsSelected = objFileDialog.ShowDialog();
 
            if (IsSelected == true)
            {
                BitmapImage bitImage = new BitmapImage();
                bitImage.SetSource(objFileDialog.File.OpenRead());
 
                //Image1 is object of Image
                Image1.Source = bitImage;
            }

the following is some codes in loading images form files in C#.

    public static void LoadImageFromFileDemo()
    {
        string fileName = "c:/Sample.png";

        REImage reImage = REFile.OpenImageFile(fileName);

    } 

with proper C# sample codes, you can load image from url and load image from graphics and other routes. thanks for the above helping.

if(userClickedOK == true){

string filename = imageDialog.FileName;
image1.Source = new BitmapImage(new Uri(filename));

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.