Изменение цвета фона ячейки в datatable - PullRequest
0 голосов

Я делаю игру Bulls and Cows в WPF И когда игрок пытается угадать. Результат будет отображаться в DataTable, который привязан к DataGrid, и я хочу сделать следующее: если число является бычьим, то задний цвет ячейки, в которую вводится это число, будет красным, а если число - корова, оно будет будь синим, пожалуйста, как это сделать?

    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++; /*what should be written here??*/ }
            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);
    }
...