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?
2 Answers
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)
-
when I write picturebox its giving warning.wpf dont allow using picturebox object.it using image object instead of picturebox– osunwaCommented Oct 20, 2012 at 10:37
-
If you want to use picturebox in wpf then you will have to use WindowsFormsHost– ganeshCommented 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?– osunwaCommented Oct 20, 2012 at 11:24
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?
-
its warning: an image source cant use as bool.it dont allow using image.source=null in if();I need another way– osunwaCommented Oct 20, 2012 at 10:42
pictureBox.Image
isnull
or not, then you need assignment, not a test for equality. Second, thePictureBox
you seem to refer to is part of the Windows Forms library, not the C# language per se.