Blog

CSS: Hide Link Text, Let Your Images Shine Through

In systems like DotNetNuke and other such CMS systems you are sometimes stuck with auto-generated links containing auto-generated text. In most cases when you are trying to make a graphically rich UI with beautiful buttons this auto-generated crap becomes a real pain. In order to let your beautiful button graphics shine through just hide the text link tag using CSS.

Setting the Width and Height to 100% and the Display to blockĀ  allows the link to expand and fill its containing element, this is useful for links on logo images making the entire image clickable. Setting the Font-Size to 0px; makes the text completely disappear from the screen but is still there.

#logo a {
width:100%; height:100%;
text-decoration:none;

display:block;
font-size:0px;}

Generic Type Conversion

This method can be used to convert the passed in object to a specified type.

internal static T Cast(object o)

Ā Ā Ā  Ā Ā Ā  {

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  T value;

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  try

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  {

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  value = (T)o;

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  }

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  catch

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  {

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  value = default(T);

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  }

Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  return value;

Ā Ā Ā  Ā Ā Ā  }

Unknown Generic Type cannot be NULL and default(T)

Lets say we are creating a generic method of type T used to convert one type into another. That being said there might be a type conversion exception thrown within the method, if this happens we want to simply return a null indicating that the conversion did not happen correctly. Unfortunately, generic types cannot be set to null, this is because a generic type could be a reference type or a value type depending on what is passed in. Because of this possibility and the fact that value types cannot be implicitly converted to null you must use a new ‘default’ keyword which checks the passed in type to see if it evaluates to a reference type or a value type, if a reference type the passed in type is set to null, if a value type it is set to the default value for that value type.

8 internal static T Cast(object o)

9 {

10 T value;

11

12 try

13 {

14 value = (T) o;

15 }

16 catch

17 {

18 value = default(T);

19 }

20

21 return value;

22 }

Silverlight Page Control Navigation

When you create a Silverlight 2.0 application the App.xaml.cs class’ OnStartup method sets the RootVisual to the page originally created at the time the solution was created. Unfortunately, the RootVisual can only be set once durring the life of the applciation.

17 private void OnStartup(object sender, StartupEventArgs e)

18 {

19 // Load the main control here

20 this.RootVisual = new Page();

21 }

If you leave the default application startup the way it is you will need to keep in mind that it can only be set once and are planning on separating out your UI into individual controls you will be stuck placing all your new controls in the default page and then hiding and displaying them as you need them. If you want to design you application with seperation of concerns as we all like to d0, and you want to place each of those controls in their own XAML Page you will need to alter the way in which the default application load happens.