![](/img/trans.png)
[英]Changing Background color when a grid row is selected in windows phone
[英]Changing color of grid in C# (Windows Phone 8)
我試圖在我簡單的應用程序中(當我單擊按鈕時)更改網格的背景顏色(名稱為“ colorPlace”)。 我試過了(紅色,綠色和藍色是字節):
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
有什么想法怎么做?
編輯:哦,我只是找到一個解決方案-元素(網格,按鈕等)中的所有更改都應在InitializeComponent();
之后完成InitializeComponent();
線。
一切看起來都很好。 項目本身出了點問題。看起來在運行時colorPlace為null。 或者您正在嘗試在InitializeComponent調用之前設置背景。
public MainPage()
{
colorPlace.Background = new SolidColorBrush(Color.FromArgb(255, 100, 100, 100));
InitializeComponent();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.