Cool C# Stuff

Begining to get to grips with the basics of C# so I thought I post a few reminders for myself.

UserControl Properties. These are just properties of a method but in Silverlight you can think of them as properties of any usercontrol.  For example you might have a button that has a ‘simple mode’ that switches of the animation and sounds.

private bool _simpleMode = false;

public bool SimpleMode
set { _simpleMode = value; }
get { return _simpleMode; }

You can then query _simpleMode before playing animations or sounds.

Resquest as syntax. Sometime you want an element as a certain class (elements can be requested as a class they inherit from).  The neatest way to do this is with the syntax below.

FrameworkElement fe = (FrameworkElement)BriefInfoUserControl;
VisualStateManager.GoToState((Control)fe, "Hide", false);

This requests a user Control as a FrameworkElement and then requests it again as a Usercontrol. Pointless but a good example 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: