Click here to Skip to main content
15,914,608 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want if that image control will contain gol1s2.gif image it will transfer to window2.xaml form otherwise it will transfer to window3.xaml form.
XML
<window x:class="WpfApplication1.Window1" xmlns:x="#unknown">
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="509">
    <grid height="275" width="271">
        <Image Margin="10,10,61,115" Grid.Row="0" Grid.Column="0"  Source="C:\Users\New1\Desktop\ba\WpfApplication1\WpfApplication1\img\gol1s2.gif" Name="image1" Stretch="Fill" />
        <Button Height="23" Margin="100,0,96,48" Name="btnSelect" VerticalAlignment="Bottom" Click="btnSelect_Click">Select</Button>
    </grid>
</window>

page behind code is
C#
string a=@"C:\Users\New1\Desktop\ba\WpfApplication1\WpfApplication1\img\gol1s2.gif";
            if(image1==a)
            {
                Window2 r=new Window2();
                r.Show();
            }
            else
            {
                 Window3 rr=new Window3();
                rr.Show();
            }


In this coding i am getting error is


Operator '==' cannot be applied to operands of type 'System.Windows.Controls.Image' and 'string'	
Posted
Updated 28-Mar-11 2:35am
v2

1 solution

You can't compare a string to an Image The variable a is a string, and the variable image1 is an Image. As far as the comparison is concerned, do you want to compare the images themselves, or just their locations?

If you hjust want to compare the locations, you can do this:

C#
if (a == image1.Source.BaseUri.AbsolutePath)
{
    // do something
}


EDIT ===============

Why was this answer voted 1? Was I wrong?
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 28-Mar-11 23:44pm    
Why, why... because the voters are the complete idiots. My 5, not just to compensate but because the answer if correct. I paid attention: the Question is duplicate, and the in the page of the first Question there are also two votes of "1" (even though that Answer is with a mistake).
OP goes to the watch list.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900