How can I change grid background image of clicked button? I tried this code but it didn't work. I need help.
Code:
WpfApplication5.Properties.Settings.Default.GridImage = "Pictures\file.jpg";
How can I change grid background image of clicked button? I tried this code but it didn't work. I need help.
Code:
WpfApplication5.Properties.Settings.Default.GridImage = "Pictures\file.jpg";
Background can be set by using ImageBrush:
var imgBrush = new ImageBrush();
imgBrush.ImageSource = new BitmapImage(new Uri(@"Pictures\file.jpg", UriKind.Relative));
myGrid.Background = imgBrush;
When using relative path, you need to have Pictures folder with file.jpg in bin\Debug folder.
Like this.You should set Background
of Button
<Grid>
<Button Name="button1" Click="button1_Click">
</Button>
</Grid>
private void button1_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("image path", UriKind.Relative);
BitmapImage img = new BitmapImage(uri);
button2.Background = new ImageBrush(img );
}