I am trying to change background color of grid (with name "colorPlace") in my simple app (when I click on button). I tried (where red, green and blue are bytes):
colorPlace.Background = new SolidColorBrush(Color.FromArgb(255, red, green, blue));
and:
colorPlace.SetValue(BackgroundProperty, "#FFFFFFFF");
And all I just get is:
An exception of type 'System.NullReferenceException' occurred in Project.DLL but was not handled in user code
Any ideas how to do it?
EDIT: Oh, I just find an solution - all changes in elements (grid, buttons etc.) should be done AFTER InitializeComponent();
line.
Everything looks good. Something wrong with the project itself.. it looks like that the colorPlace is null at the runtime. or you are trying to set the background before the InitializeComponent call.