Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have create a list of background images. i want to set the background image of a canvas by selecting the image from that list at runtime. so please help me how i do it. thanks

What I have tried:

private void Backgrounds1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//var selecteditem = e.AddedItems[0] as BackgroundImageLIstMOdel;
//if (selecteditem != null)
// {
Backgrounds1.Visibility = Visibility.Collapsed;
// My_canvas.Background = new BitmapImage(new Uri(selecteditem.Imageurl, UriKind.RelativeOrAbsolute));

//}
my_canvas.Visibility = Visibility.Visible;

}
Posted
Updated 8-Dec-16 22:12pm

C#
ImageBrush ib = new ImageBrush();
ib.ImageSource = new BitmapImage(new Uri(selecteditem.Imageurl, UriKind.RelativeOrAbsolute));
My_canvas..Background = ib;
 
Share this answer
 
Comments
vikas sharawat 2-Jun-16 0:51am    
thank you very much sir it have solved my problem
on focus() that background image gets hide..
 
Share this answer
 

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