Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code

int n=1;
    private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (n == 1)
        {
            myStoryboard.Begin(this);
            myStoryboarda.Begin(this);
            BitmapImage img = new BitmapImage();
            img.BeginInit();
            img.UriSource = new Uri("pack://application:,,/Resources/MB2.png");
            img.EndInit();
            image1.Source = img;
            n = 2;
        }
        else
        {
            myStoryboard2.Begin(this);
            myStoryboardb.Begin(this);
            BitmapImage img = new BitmapImage();
            img.BeginInit();
            img.UriSource = new Uri("pack://application:,,/Resources/MB2.png");
            img.EndInit();
            n = 1;
        }
    }


and i get an error on this line
img.EndInit();


and the error says

Cannot locate resource 'resources/mb2.png'.

and my resource is called " MB2 " and it is a png in my resources. and for some reason it just doesn't work and i don't know why, can some one please help me?
Posted

create resource in the App.xaml

XML
<ImageSource x:Key="test1">banner_img_1.jpg</ImageSource>
<ImageSource x:Key="test2">banner_img_2.jpg</ImageSource>


Now change the source like that

C#
private void image1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
       {
           image1.Source = this.FindResource("test2") as ImageSource;
       }
 
Share this answer
 
Comments
[no name] 30-Jul-11 21:08pm    
i get an error saying, resource not found
nit_singh 2-Aug-11 10:42am    
Where did you created the resources in the App.xaml file?
This could be an issue with the url path.
Just try new URI(/Resources/MB2.png).
 
Share this answer
 
Comments
[no name] 30-Jul-11 8:56am    
i get this error: Invalid URI: The format of the URI could not be determined.

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