Hi,

I am a beginner, and trying to call an image inside a form.
So basically, I have done a simple WPF application in which if I press a button, I will managed to show an image in my main form. So, the code is below :

private void btnAddMore_Click(object sender, RoutedEventArgs e)
        {
          FunctImage();
        }

        public void FunctImage()
        {
            System.Windows.Controls.Image img = new Image();
            img.Source = new BitmapImage(new Uri(@"C:\bla.jpg"));
            img.Width = 200;
            Content = img;
        }

I tried to implement this function in a server (one window form with a button). And if I press a button, the client would start listening for the client. If the client send a string (e.g. "send"), the server would accept this string, and call the FunctImage above. I have debugged it, I received the "send" string, however when the FunctImage is called, my main form is hang. I tried to go around with it, but until know, it does not work. So, the code is below

string newTest = Encoding.ASCII.GetString(data, 0, recv);
                if (newTest.Equals("send"))
                {
                //if I show another form outside the main form, it work just fine.E.G:
                //MessageBox.Show("String received"); //this Message box is shown outside //the main form sucessfully, after server received the string from client


                    //if I call the FunctImage, the main forms can not show the  image,hang.. 
                    FunctImage();
               }
                ns.Write(data, 0, recv);

            }
            ns.Close();
            client.Close();
            newsock.Stop();

Thank you for the guidance.. Any small tips will be very useful.

Two questions which might help:
1. Is there a file at "C:\bla.jpg" on the server?
2. What is 'Content' ?

it is a default function to call the image. However *very unfortunate* I can not find any adequate explanation for "content". For my problem, I think it is solvable by using delegates. There is a problem with updating the UI from other thread, so I am currently trying to understand this .. I will dig deeper into this. Thank you for all of your responses, appreciate it so much!..

This question has already been answered. Start a new discussion instead.