So I made a custom control, containing a button and an image. I create 64 of them, a chessboard.
for (int i = 1; i <= 8; i++)
{
for (int j = 1; j <= 8; j++)
{
Square field = new Square(i, j, this);
field.Click += OnFieldClick;
squares[i - 1, j - 1] = field;
squares_list.Add(field);
Square_control fieldBase = new Square_control(field);
this.table.Children.Add(fieldBase);
Grid.SetRow(fieldBase, j - 1);
Grid.SetColumn(fieldBase, i - 1);
}
}
Square is a class inheriting from Button class. It's background is set in it's constructor.
Square_Control is my custom control containing a button and an image. Its constructor sets the button to the parameter.
Thanks to the debugger, I found out that colors black and white are set properly in the field and fieldBase objects, but when I run the program all the buttons are white.
I feel like I'm missing some important knowledge about how WPF works.
Square constructor:
public Square(int row, int col, MainWindow wind)
{
if ((row + col) % 2 == 0)
isWhite = true;
else
isWhite = false;
colName = col;
rowName = row;
if (this.isWhite)
SquareColor = wind.BasicWhite;
else
SquareColor = wind.BasicBlack;
Background = SquareColor;
window = wind;
}
BasicWhite = new SolidColorBrush(new Color()
{
R = 255,
B = 255,
G = 255,
A = 255
});
BasicBlack = new SolidColorBrush(new Color()
{
R = 0,
B = 0,
G = 0,
A = 255
});
Square_control xaml:
<Button x:Name="SQR">
<Image x:Name="FigImage"/>
</Button>
It's constructor:
public Square_control(Button butt)
{
InitializeComponent();
SQR = butt;
}
Also, I tried setting background color in Square_Control directly in XAML and it worked.
Squareclass code so we can try to help - Rafalon