I'm making Bulls and Cows game in WPF And when the player tries to guess. The result will be displayed in DataTable which is banded to DataGrid and I want to do the next: if the number is bull then the backcolor of a cell which that number is put in will be red, and if the number is cow, it will be blue, so how to do that please?
- void filldatagrid()
- {
- table.Columns.Add("N1", typeof(int));
- table.Columns.Add("N2", typeof(int));
- table.Columns.Add("N3", typeof(int));
- table.Columns.Add("N4", typeof(int));
- table.Columns.Add("Cows", typeof(int));
- table.Columns.Add("Bulls", typeof(int));
- showing.ItemsSource = table.DefaultView;
- }
- private void Grid_Loaded(object sender, RoutedEventArgs e)
- {
- filldatagrid();
- }
- private void comparing()
- {
- int a, b, c, d, cows = 0, bulls = 0;
- a = (gussing / 1000) % 10;
- b = (gussing / 100) % 10;
- c = (gussing / 10) % 10;
- d = gussing % 10;
- if (a == number[0] && b == number[1] && c == number[2] && d == number[3])
- {
- UserInput.Visibility = Visibility.Hidden;
- _try.Visibility = Visibility.Hidden;
- win.Visibility = Visibility.Visible;
- thenumber.Visibility = Visibility.Visible;
- thenumber.Content = "The nubmber" + gussing.ToString();
- }
- else
- {
- if (a == number[0])
- {
- bulls++;
-
- }
- else if (a == number[1] || a == number[2] || a == number[3])
- cows++;
- if (b == number[1])
- bulls++;
- else if (b == number[0] || b == number[2] || b == number[3]) cows++;
- if (c == number[2])
- bulls++;
- else if (c == number[0] || c == number[1] || c == number[3])
- cows++;
- if (d == number[3])
- bulls++;
- else if (c == number[0] || c == number[1] || c == number[2])
- cows++;
- }
- table.Rows.Add(a, b, c, d, cows, bulls);
- }