在C#中更改网格的颜色(的Windows Phone 8) [英] Changing color of grid in C# (Windows Phone 8)

查看:193
本文介绍了在C#中更改网格的颜色(的Windows Phone 8)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的简单的应用程序来改变网格的背景颜色(名称为colorPlace)(当我点击按钮)。我试过(其中红色,绿色和蓝色字节):

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));

colorPlace.SetValue(BackgroundProperty, "#FFFFFFFF");

和所有我得到的是:

An exception of type 'System.NullReferenceException' occurred in Project.DLL but was not handled in user code

$ 2 b
$ b

任何想法如何做到这一点。

Any ideas how to do it?

编辑:呵呵,我只找到一个解决办法 - 在所有元素的变化(网格,按钮等)应在的InitializeComponent()来完成;

Oh, I just find an solution - all changes in elements (grid, buttons etc.) should be done AFTER InitializeComponent(); line.

推荐答案

一切都看起来不错。蹊跷的项目本身..
,它看起来像该colorPlace在运行时为空。
或您要设置InitializeComponent调用之前的背景。

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.

public MainPage()
        {
            colorPlace.Background = new SolidColorBrush(Color.FromArgb(255, 100, 100, 100));
            InitializeComponent();    
        }

这篇关于在C#中更改网格的颜色(的Windows Phone 8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆