Click here to Skip to main content
15,075,944 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I am trying to set the Textbox control's color in runtime like;

TextBox1.Foreground = Brush.White;

I get an Error: 'System.Windows.Media.Brush' Does not contain a difinition for 'White'

The Code is:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Threading;

namespace Test1
{
    public partial class MainPage : PhoneApplicationPage
    {
	private DispatcherTimer _timer;
        

        public MainPage()
        {
            InitializeComponent();
        }

        public void RefreshUI(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;
            if (dt.Day == 1)
            {
                TextBox1.Foreground = Brush.White;
            }
        }
    }
}


Thanks in advance.
Posted

1 solution

   
Comments
Dave Crump 21-Aug-12 0:13am
   
Thank you, I was in this MSDN page, but still I don't know how to set the Brush.
Can you help me with an example?
   
Can you read, anyway? Kenneth told you exactly: Change "Brush" into "Brushes". If you failed to see it in the two-line answer, I can imagine how successful could be your reading of MSDN. I don't believe you have such a big cognitive problem; perhaps, just slow down.
--SA
   
5ed.
--SA
Kenneth Haugland 21-Aug-12 1:24am
   
Thanks Sergey :)
Kenneth Haugland 21-Aug-12 14:48pm
   
OP has a remark to you, see below :)
Dave Crump 21-Aug-12 14:30pm
   
@Sergey: First of all, keep your manner. Here is a development's forum not a standup comedy. Second: You can beleive in what you like, but you are not in the position to judge upon anybody.
Back to work: I tried already Brushes instead of Brush, I get the same Error. Does not matter if I code TextBox1.Foreground = Brushes.White; or TextBox1.Foreground = Brush.White;
DO I have the right using in my header.

Regards,
Kenneth Haugland 21-Aug-12 14:43pm
   
I have verified that it works with Brushes.White, before I posted it. I dont think it work with Brush becouse it holds several different types of Brushes; Sollid/Linear/Gradient Brush, while Brushes is a SolidColorBrush. :)

http://msdn.microsoft.com/en-us/library/system.windows.media.brush.aspx
Dave Crump 21-Aug-12 14:46pm
   
Thanks, I have got it already.
Kenneth Haugland 21-Aug-12 15:15pm
   
Please mark it as answer if it worked for you :)

PS: If you press reply by houlding your mouse over the comment you whish to respond to the person that made the comment would get an e-mail, if you press Have a Question comment? button only the one that answered the question will get the e-mail.
Dave Crump 21-Aug-12 15:29pm
   
Sure I will do that so long it works really. In fact still I have the same problem. Error-ID is; (Compiler Error CS0103 "The name 'Brushes' does not exist in the current context") So, as you might see, I have the "System.Windows.Media" in my header. Do I have to define it again?
Did you know that I am trying to develop on Windows Phone 7.1?

Regards,
Kenneth Haugland 21-Aug-12 15:33pm
   
you could type in the full namespace:
System.Windows.Media.Brushes.White
and see if that works, but I dont get that error. You could also try to remove the Using block.
Dave Crump 21-Aug-12 16:05pm
   
Did you know, I am coding on Windows-Phone Project?
Can it be cause of the problem, that I can not use the System.Windows.Media.Brushes.White? It says "Are you missing an Assembly reference?"

Regards,
Kenneth Haugland 21-Aug-12 16:46pm
   
And you tell us this now? Thanks for that!
TextBox1.Foreground = new SolidColorBrush(Colors.White);
Dave Crump 21-Aug-12 16:49pm
   
Sorry about that!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900