Right now we are adding images to the xamcarouselpanel in the xaml code.
But I want to add them dynamically in codebehind file(C#).
How can I do this?
Hello,
The XamCarouselPanel exposes a ChildElements collection which stores the elements in the CarouselPanel. You can add the images directly in this collection.
xamCarouselPanel1.ChildElements.Add(new Button() { Content = "Button", Width = 100, Height = 100 });
Hope this helps.
Thanks Alex,
but it is not working, I tried like this
Uri ImageUri = null;
ImageUri = new Uri(@"D:\Ravinder\Ravi\personal\RP\personal\me1.JPG", UriKind.Relative);
img.Source = image;
img.Width = 150;
img.Height=150;
CarouselPanel.ChildElements.Add(img);
but it is not displaying any images. Am i missing any settings?
Please let me know?
The path you have provided is not relative. It is absolute. Relative is if it is in the project directory.
You can set the UriKind to RelativeOrAbsolute.
Hi Alex,
i am adding the images dynamically using the following code. but it is not displaying any images in carousel panel.
What is the problem? Am i missing any thing? Please let me know..
Uri ImageUri = null; ImageUri = new Uri(@"D:\Imagesr\Image\personal\emp1.JPG"); BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = ImageUri; Image im = new Image(); im.Width = 50; im.Height = 50; im.Source = image; image.CacheOption = BitmapCacheOption.Default; image.EndInit(); CarouselPanel.ChildElements.Add(image);
Its working fine...
Uri ImageUri = null; ImageUri = new Uri(@"D:\Imagesr\Image\personal\emp1.JPG"); BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = ImageUri; Image im = new Image(); im.Width = 50; im.Height = 50; im.Source = image; image.CacheOption = BitmapCacheOption.Default; image.EndInit(); CarouselPanel.ChildElements.Add(im);
Did you find what was the reason for this ? Incorrect uri?
Yes Alex,
Thanks