1

I want to control my image object is or is not null. if(pictureBox.Image == null) works C# but I cannot find a code for WPF. What should I write for this?

1
  • If you want to control whether pictureBox.Image is null or not, then you need assignment, not a test for equality. Second, the PictureBox you seem to refer to is part of the Windows Forms library, not the C# language per se. Commented Oct 20, 2012 at 10:36

2 Answers 2

1

YOu can do this :-

     private PictureBox p1= null;

Now you can set the value as null

     p1= (PictureBox)image;

And finally you can use it as:-

    if(p1 == null)
4
  • when I write picturebox its giving warning.wpf dont allow using picturebox object.it using image object instead of picturebox
    – osunwa
    Commented Oct 20, 2012 at 10:37
  • If you want to use picturebox in wpf then you will have to use WindowsFormsHost
    – ganesh
    Commented Oct 20, 2012 at 10:40
  • @osunwa:- if you dont want to add the WindowwsFormsHost then "keyboardP" has given you a solution which would have been my second answer Commented Oct 20, 2012 at 10:43
  • Can I solve problem without using picturebox.is image object insufficient for my request?
    – osunwa
    Commented Oct 20, 2012 at 11:24
1

WPF doesn't have a PictureBox control. The equivalent is Image (as shown here), so you could just do this:

if(myImage.Source == null) ...

Unless you're doing something more complicated and hosting WinForm controls in WPF?

1
  • its warning: an image source cant use as bool.it dont allow using image.source=null in if();I need another way
    – osunwa
    Commented Oct 20, 2012 at 10:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.