I am creating a tic tac toe game for windows 8.1 store using xaml and c# and was trying to change the X and O button on click. Initially, I have a blank image set in the xaml for the button and in the button_click event, I am trying to change the image source. Here is a snippet of my code:
private void Button_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
if (turn == 1)
{
BitmapImage bmp = new BitmapImage();
Uri u = new Uri("ms-appx:/Images/O_logo.png", UriKind.RelativeOrAbsolute);
bmp.UriSource = u;
ImageBrush i = new ImageBrush();
i.ImageSource = bmp;
btn.Background = i;
}
else
{
BitmapImage bmp = new BitmapImage();
Uri u = new Uri("ms-appx:/Images/X_logo.png", UriKind.RelativeOrAbsolute);
bmp.UriSource = u;
ImageBrush i = new ImageBrush();
i.ImageSource = bmp;
btn.Background = i;
}
btn.IsEnabled = false;
//win(btn.Content.ToString());
turn += 1;
if (turn > 2)
turn = 1;
}
I have read a few articles online and some of them suggested that I set the build action of my image to Resource, however I do not have that as an option. I have PRIResource and Embedded Resource as an option. I have very limited knowledge of mvvm and triggers and hence would like to solve the problem using wpf itself and not in xaml.
I am using VS Studio Professional 2013
ToggleButtonwith X & O for theIsCheckedtrue/false states? Seems like extra work this way.