Reputation: 1218
In this case how can i change the background programmatically ?
<Button x:Name="ButtonPlayBack1" Tag="0" Grid.Column="1" Height="60" Width="70" Click="ButtonPlayBack_OnClick">
<Button.Template>
<ControlTemplate>
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/Assets/images/bubble_right_grey.png"/>
</Grid.Background>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
Upvotes: 0
Views: 152
Reputation: 1218
The solution :
Grid grid = ButtonPlayBack1.GetLogicalChildrenByType<Grid>(true).First();
if (grid != null)
grid.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri(backGroundSrc, UriKind.Relative)) };
Upvotes: 0
Reputation: 2621
try this:
XAML:
<Button x:Name="ButtonPlayBack1" Tag="0" Grid.Column="1" Height="60" Width="70" Click="ButtonPlayBack1_Click" BorderThickness="0">
<Button.Background>
<ImageBrush ImageSource="/Assets/images/bubble_right_grey.png"></ImageBrush>
</Button.Background>
</Button>
CS:
private void ButtonPlayBack1_Click(object sender, RoutedEventArgs e)
{
BitmapImage bit = new BitmapImage(new Uri("/Assets/AlignmentGrid.png", UriKind.Relative));
ImageBrush brush = new ImageBrush();
brush.ImageSource = bit;
ButtonPlayBack1.Background = brush;
}
Upvotes: 2