Solved

WPF x:static and brushes/colors

Posted on 2010-11-07
4
1,270 Views
Last Modified: 2013-11-12
I'm working with a training course and it is throwing an error about not completing the exercises propertly.

In a nut shell, I need to define brushes using the x:Static syntax, and while what I wrote works, it is telling me that I'm using the wrong classes.

I built the XAML using this:
<Rectangle Grid.Row="1" Fill="{x:Static SystemColors.GrayTextBrush}"></Rectangle>

And the error is this:
"The Rectangle is not filled with a color from the Colors class."

I've got another one for a border that says:
"The Border element in the SampleWindow.xaml file does not specify a background color using any brush in the Brushes class."


What do I need to change here?
0
Comment
Question by:PixelMuse
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:MikeToole
ID: 34083638
Does the course material insist on using the x:static syntax? I would code it as:
<Rectangle Grid.Row="1" Fill="Gray"></Rectangle>

Can you post the xaml for the border that's giving problems
0
 

Author Comment

by:PixelMuse
ID: 34083653
Yes, it says to use the x:static syntax. Here is the whole little layout lesson, so you can see what it is asking for. The border code is there too.
<Window x:Class = "Task.SampleWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		Title="SampleWindow" Height="302" Width="574">
	<Grid Name="windowGrid">
		<Grid.RowDefinitions>
			<RowDefinition Height="*" />
			<RowDefinition Height="*" />
		</Grid.RowDefinitions>
        <Border Background="{x:Static SystemColors.HighlightTextBrush }" Padding="5">
            <Button>
                <Button.Background>
                    <ImageBrush ImageSource="logo.gif"/>
                </Button.Background>
            </Button>
        </Border>
        
        <Rectangle Grid.Row="1" Fill="{x:Static SystemColors.GrayTextBrush}"></Rectangle>
            <!--
			Todo:
			The SampleWindow.xaml XAML file declares a single Border element within the
			 <Grid> tags that uses markup extension syntax to specify a background color
			 using any brush in the Brushes class. The Border element has padding of 5 units
			 on each side.
		-->
		<!--
			Hint:
			There are a variety of ways to set the Background property of a Border object, but 
			 you should look at the x:Static reference provided in the links section for an 
			 example of the syntax required.
		-->
		
		<!--
			Todo:
			The Border element declared in the SampleWindow.xaml XAML file contains a Button
		 	 control as a child element. The Button control uses property element syntax to
		 	 set the background property to an ImageBrush Brush with an ImageSource property
		 	 of logo.gif.
		-->

		<!-- 
			Hint 
			To create an ImageBrush brush with ImageSource property of logo.gif
			 you can use the following markup: <ImageBrush ImageSource="logo.gif" />
		-->


		<!--
			Todo:
			The SampleWindow.xaml XAML file declares a Rectangle element within the <Grid>
			 tags, which is filled with any color defined on the Colors class using attribute
			 syntax.
		-->

		<!--
			Todo:
			The Rectangle declared in the SampleWindow.xaml XAML file is assigned to the
			 second row of the containing grid, using attached property syntax.
		-->
		
		<!--
			Hint:
			The rows and columns of a Grid control are identified using a zero-based index. 
			 You should take this into account when assigning a control to a particular row 
			 or column.
		-->

	</Grid>
</Window>

Open in new window

0
 
LVL 27

Accepted Solution

by:
MikeToole earned 500 total points
ID: 34083812
It asks to select a member of the Brushes class, not SysttemColors, try this:
Fill="{x:Static Brushes.Gray}"
0
 

Author Closing Comment

by:PixelMuse
ID: 34132129
I don't know why I didn't try that. I start typing "Brushes", but intellisense didn't pick it up so I decided not to continue.

Thanks.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio Exe Issue, 12 30
Event ID 10010 3 61
Messagebox for a Web Site Application 4 71
Is AWS.RDS considered a part of "Big Data"? 4 110
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question