Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have one Canvas which contain StackPanel. And that panel contains image and i want to change path of that image.

Here is my code which is working fine.But my query is, is it possible to change path of that image out of function loop?.
C#
Load Image(String Name)
{
   panel = new StackPanel();
   panel.Orientation = Orientation.Vertical;
                        
   path = "pack://siteoforigin:,,/cam.jpeg";

   imgLoc = new Uri(path, UriKind.RelativeOrAbsolute);
   imgId = new BitmapImage(imgLoc);
   img = new Image();
   img.Source = imgId;
   img.Width = 15;
   img.Height = 15;
   img.HorizontalAlignment = HorizontalAlignment.Left;
                       
   panel.Children.Add(img);                       
   panel.ToolTip = Name;
   panel.DataContext = Name;

   double Xcoordinatee = (Convert.ToDouble(Xcoordinate) * ImageHolder.ActualWidth);
   double Ycoordinatee = (Convert.ToDouble(Ycoordinate) * ImageHolder.ActualHeight);

   //set camera's x-coordinate
   Canvas.SetLeft(panel, Xcoordinatee);
   //set camera's y-coordinate
   Canvas.SetTop(panel, Ycoordinatee);

   panel.Opacity = 0.85;

   panel.Width = img.Width;
   panel.Height = img.Height;

   //restrict dropped camera image to be in map image area
   if (Xcoordinatee + panel.Width > ImageHolder.Width)
   {
      Canvas.SetLeft(panel, ImageHolder.Width - panel.Width);
   }

   if (Ycoordinatee + panel.Height > ImageHolder.Height)
   {
      Canvas.SetTop(panel, ImageHolder.Height - panel.Height);
   }

   ImageHolder.Children.Add(panel);
Posted
Updated 7-Dec-11 14:20pm
v3
Comments
Sergey Alexandrovich Kryukov 7-Dec-11 9:50am    
How is this related to "color of canvas"?
--SA
Sergey Alexandrovich Kryukov 7-Dec-11 9:51am    
What loop?! There is no loops in your code.

The question does not seem to have any sense.
--SA
KIDYA 7-Dec-11 10:13am    
want to change this path of image -> path = "pack://siteoforigin:,,/cam.jpeg";
[no name] 7-Dec-11 20:20pm    
EDIT: added formatting

1 solution

Not clear about your looping condition
 
Share this answer
 
Comments
KIDYA 7-Dec-11 10:14am    
want to change this path of image in above code -> path = "pack://siteoforigin:,,/cam.jpeg"; out of function LoadImage()

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