Did You Know : The difference in a Rectangle with or without a Fill in Silverlight/WPF?

by rahul 10/25/2010 9:34:20 AM

Check out the following XAML and notice the difference in Fill of the following three rectangles.

        <StackPanel>
            <Rectangle Stroke="Black" StrokeThickness="3" Width="100" Height="100"
                   Margin="5" MouseLeftButtonUp="rect_MouseLeftButtonUp" Fill="Transparent" />
            <Rectangle Stroke="Black" StrokeThickness="3" Width="100" Height="100"
                   Margin="5" MouseLeftButtonUp="rect_MouseLeftButtonUp" Fill="{x:Null}" />
            <Rectangle Stroke="Black" StrokeThickness="3" Width="100" Height="100"
                   Margin="5" MouseLeftButtonUp="rect_MouseLeftButtonUp" />
        </StackPanel>

As you can see, the first rectangle has Transparent fill, 2nd one has Null fill, and the third one doesn't talk about Fill at all. You can
easily guess how it would appear…

image

So, what's the difference? Well… it is a very subtle one. Write a code for rect_MouseLeftButtonUp as follows…

private void rect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    MessageBox.Show("Test");
}

You will find that the first rectangle will respond wholly to click. The border, and the empty area as well. For the 2nd and 3rd
rectangle, you will not get any message box if you click in the empty area. Borders will respond though. Thus, 2nd and 3rd are rectangles are similar.

Until next time, Wave
Rahul


Quote of the day:
I never teach my pupils. I only attempt to provide the conditions in which they can learn. - Albert Einstein


blog comments powered by Disqus

Rahul Soni

Rahul Soni  Twitter

 LinkedIn

 Facebook

 Email me



Vivek Kumbhar

Vivek Kumbhar  Twitter

 LinkedIn

 Facebook

 Email me


Stack Exchange

profile for Vivek at Server Fault, Q&A for system administrators and IT professionals

profile for Rahul Soni at Stack Overflow, Q&A for professional and enthusiast programmers

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

All Items
Sign in

Visit Microsoft's Site

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2012, Rahul Soni

Powered by BlogEngine.NET 1.4.5.0