locked
TextBox color RRS feed

  • Question

  • Newb question...I have a TextBox in my silverlight app and I want to change the background color of the TextBox. I have the following line of code in my Page.xaml:

    <TextBlock Background="Black" Foreground="Maroon" Text="{Binding Title.Text}" />

    And it seems to complain about the property "Background" - I get the following errors / warnings:

    1. Warning    1    The property 'Background' does not exist on the type 'TextBlock' in the XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.    C:\Users\nkumar\Documents\Visual Studio 2008\Projects\RSSFeedReader\RSSFeedReader\Page.xaml    16    36    RSSFeedReader

    2. Error The property 'Background' was not found in type 'TextBlock'.    C:\Users\nkumar\Documents\Visual Studio 2008\Projects\RSSFeedReader\RSSFeedReader\Page.xaml    16    36    RSSFeedReader


    Any idea whats wrong?



    Monday, August 25, 2008 5:18 PM

Answers

  • Hi nkkumar,

    First you have to set the name for the control (which is the x:Name property), you can set it in Expression Blend by selecting the control and then going to the properties pane (located on your upper right along with your project and resources pane), and change the name property to a value, e.g: textblock1.

    In your code behind, add this line of code in any event you like, maybe a button click:

    textblock1.Background = Brushes.Black;

    And when the button is clicked it will turn to black color.

    Hope this helps :)

    -
    Tuesday, August 26, 2008 2:22 AM