Blog


Extension Method: Hex To Color

Below you have an extension method that can help you convert any hex color code to a Color object.

public static Color ToColor(this string hexColor)
{
   return Color.FromArgb(
      Convert.ToByte(hexColor.ToString().Substring(1, 2), 16),
      Convert.ToByte(hexColor.ToString().Substring(3, 2), 16),
      Convert.ToByte(hexColor.ToString().Substring(5, 2), 16),
      Convert.ToByte(hexColor.ToString().Substring(7, 2), 16));
}

The method above can only convert 8 characters ARGB color codes.
In order to convert simple RGB codes too we will check for the length of the string (9 = ARGB and 7 = RGB) and in case it’s 7 we will add the alpha to our string as FF ( 255 – opaque) and only then return the color.

public static Color ToColor(this string hexColor)
{
   string tempHexColor = string.Empty;
   if (hexColor.Length == 7)
      tempHexColor = "#FF" + hexColor.Substring(1,6);
   return Color.FromArgb(
      Convert.ToByte(tempHexColor.Substring(1, 2), 16),
      Convert.ToByte(tempHexColor.Substring(3, 2), 16),
      Convert.ToByte(tempHexColor.Substring(5, 2), 16),
      Convert.ToByte(tempHexColor.Substring(7, 2), 16));
}

We should also do something in case the hex color code is not actually a hex color code. So add another if statement after the one we added already and check again for the length of the string; if it’s not equal to 9 then it’s not good so feel free to return any color you want (I will return transparent). The final method looks like this:

public static Color ToColor(this string hexColor)
{
   string tempHexColor = string.Empty;
   if (tempHexColor.Length == 7)
      tempHexColor = "#FF" + hexColor.Substring(1,6);
   if (tempHexColor.Length != 9)
      tempHexColor = "#00000000";
   return Color.FromArgb(
      Convert.ToByte(tempHexColor.Substring(1, 2), 16),
      Convert.ToByte(tempHexColor.Substring(3, 2), 16),
      Convert.ToByte(tempHexColor.Substring(5, 2), 16),
      Convert.ToByte(tempHexColor.Substring(7, 2), 16));
}

How to use it:

string myHexString = "#78196DFD";
Color myColor = new Color();
mycolor = myHexString.ToColor();



Windows Phone 7: Getting the current GPS location from the device

Getting the current GPS location on a Windows Phone device is rather easy. In order to start you will need to add a reference to System.Device in your project and then a using statement inside the class that you want to get the geo-location.

using System.Device.Location;

Next we would need to declare an object of type GeoCoordinateWatcher. For better access I will declare it as a class member and not as a local variable inside some method.

GeoCoordinateWatcher geoWatcher = null;

Next to do is: create an instance of GeoCoordinateWatcher, create an event handler for the position changed event and then start reading the data. So, to create an instance of GeoCoordinateWatcher go to the class constructor and copy the following code:

geoWatcher = new GeoCoordinateWatcher();

This will create a GeoCoordinateWatcher object in the variable we previously declared. In case the location you need has to have a certain accuracy, the class provides you with an overload for the contructor which takes your desired accuracy as a parameter.

geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);

Next create an event handler for the PositionChanged event. You can do this by typing geoWatcher.PositionChanged += and then press the TAB key twice; this will automatically create the event handler for you. After creating the event handler, all you need to do is use geoWatcher.Start() to start reading coordinates. Now your code should look like this:

GeoCoordinateWatcher geoWatcher = null;
public MainPage()
{
   InitializeComponent();
   geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
   geoWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(geoWatcher_PositionChanged);
   geoWatcher.Start();
}

void geoWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
   throw new NotImplementedException();
}

Next we want to get the coordinates for our location. That is really simple. You can get them in a GeoCoordinate object by accesing e.Position.Location in the event handler, or if you want to get them as individual values you can save e.Position.Location.Latitude, e.Position.Location.Longitude and e.Position.Location.Altitude in three double variables. Example below:

void geoWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
   GeoCoordinate currentLocation = e.Position.Location;
   double currentAltitude = e.Position.Location.Altitude;
   double currentLongitude = e.Position.Location.Longitude;
   double currnetLatitude = e.Position.Location.Latitude;
}

That’s it. Now if you want to get rid of the object and stop reading the current location after reading the first set of values you can simply add the following lines of code to the event handler. Otherwise you can create a method for it and call it whenever you wish.

geoWatcher.Stop();
geoWatcher.Dispose();
geoWatcher = null;

In order to test the code I just wrote I will add three textboxes to my application in which I will write the data I read in them. You can do the same. Anyways that’s it. If you got any questions leave a comment and I’ll answer them asap.

You can get the project from here:Download for Windows Phone




Windows 8 Demo from CES 2012

  • January 15, 2012
  • CES, Metro, ...

This is the demo Microsoft made at CES this year demonstrating some of the new features of the upcoming Windows 8. One of the features that caught my attention was the Windows Store which they say it will open in late February. A new build of Windows 8 is also said to come in late February.

Also, in the video there’s a small presentation of a HTML5 app called Cut the Rope – really nice app in my opinion. Can’t wait to try it out myself.




How To: Create your own code snippets

Okay, so what I will do here is explain you how to create your own code snippets to use in Visual Studio 2010 without using any add-ins related to snippet designing. A post on snippet designers / explorers and how you can use them to build better snippets faster will come sometime next week I believe, but this time I can’t promise.

PART 1: CREATING A SIMPLE CODE SNIPPET

So let’s get started. Open up your Visual Studio and go to File – New File (or Ctrl + N) and create a new XML file. Don’t worry about the file’s name at this point as it is not that important. An XML file with a line of code will automatically be generated for you. So, the first thing we need to do in this brand new file is to add the CodeSnippets namespace and a CodeSnippet element to it right after the first line; to do so copy-paste the code below:

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
   <CodeSnippet Format="1.0.0">
   </CodeSnippet>
</CodeSnippets>

Now we can really start work on our snippet. First thing we need to do is set up the header of our snippet. The header can contain various information like the Title, Description, Author,  Keywords in case you want to make your snippet available online, a Shortcut for your snipped and also a HelpUrl where people can go and ask for help in case something doesn’t work as expected. I suggest you always add a title and a description to your snippets even if they are not mandatory.

Here’s an example of a header containing all possible elements:

<Header>
   <Title>MessageBox</Title>
   <Description>Opens up a message box displaying "Hello World!".</Description>
   <Author>StartDebugging.net</Author>
   <Keywords>
      <Keyword>messagebox</Keyword>
      <Keyword>helloworld</Keyword>
   </Keywords>
   <Shortcut>hellobox</Shortcut>
   <HelpUrl>http://startdebugging.net</HelpUrl>
</Header>

Now that the header is set up, we can start writing the code. First thing here is creating the actual Snippet element right after the end of the Header element. Your code should look like this now:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
   <CodeSnippet Format="1.0.0">
      <Header>
         ...
      </Header>
      <Snippet>
      </Snippet>
   </CodeSnippet>
</CodeSnippets>

The code which we want the snipped to insert must be added in the Code element of the Snippet between <![CDATA[ and ]]> brackets. In this example, as you’ve probably figured out from the description, our code snippet will simply display a message box containing the text “Hello World!”.  Bellow you can see how the Code element of the snippet looks like after adding the code.

<Snippet>
   <Code Language="CSharp">
      <![CDATA[MessageBox.Show("Hello World!");]]>
   </Code>
</Snippet>

As you can see above, my Code element has a property named Language which is set to CSharp. Make sure that you set that language accordingly. You can write code snippets for VB, CSharp, VJSharp and XML.

Also, another element which you can add to the Snippet is References. Unfortunately this is not supported for C# so you will have to add them manually in our case. Otherwise, here’s how you can add a reference:

<Snippet>
   <References>
      <Reference>
         <Assembly>System.Windows.Forms.dll</Assembly>
      </Reference>
   </References>
   <Code Language="VB">
      ...
   </Code>
</Snippet>

So here’s the entire code of the snippet:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
   <CodeSnippet Format="1.0.0">
      <Header>
         <Title>MessageBox</Title>
         <Description>Opens up a message box displaying "Hello World!".</Description>
         <Author>StartDebugging.net</Author>
         <Keywords>
            <Keyword>messagebox</Keyword>
            <Keyword>helloworld</Keyword>
         </Keywords>
         <Shortcut>hellobox</Shortcut>
         <HelpUrl>http://startdebugging.net</HelpUrl>
      </Header>
      <Snippet>
         <Code Language="CSharp">
            <![CDATA[MessageBox.Show("Hello World");]]>
         </Code>
      </Snippet>
   </CodeSnippet>
</CodeSnippets>

Now that we’re done writing the snippet it’s time to save it. So File – Save as to the following path:

Drive:\...\Documents\Visual Studio Version\Code Snippets\Language\

which in our case is

Drive:\...\Documents\Visual Studio 2010\Code Snippets\Visual C#\

using the .snippet file extension – for example messagebox.snippet.

Now that you’ve saved it, it’s time to add it to your Visual Studio 2010. So go to Tools – Code Snippets Manager (or Ctrl + K, Ctrl + B), click on Import  and open the snippet we previously saved. After opening it you will be asked to which languages to add it, in our case simply check Visual C#.

Create a new project or open an already existing one (C# project) and go somewhere where you can write some C# code. Now, inserting a snippet can be done two ways: one – hit Ctrl + K, Ctrl + X, select Visual C# (or any other language for that matter) and then select the snippet you want to insert (ours is called MessageBox – we set this name using the Title tag); – second way is by typing the shortcut (ours is called hellobox – we set this name using the Shortcut tag in the header) and pressing double TAB. And there you go, your snippet is inserted.

PART 2: USING LITERALS

Now that you know how to create, save and use a code snippet it’s time to learn how to create a little bit more complex ones – and here I’m referring to literals.

Since I couldn’t think of a better definition for literals, here’s the one I found on msdn:

The Literal element is used to identify a replacement for a piece of code that is entirely contained within the snippet, but will likely be customized after it is inserted into the code.

So let’s say you have a code snippet in which you use a variable name 10 times. You insert that code snippet into your code and you decide that the variable name must be changed so you go ahead and replace the old variable name with the new variable name in all 10 cases. What literals allow you to do is define a piece of code inside your snippet which you can use several times, and after you insert that snippet into your code if you change that defined piece of code in one place, then it will change in all the other places where you used it. You can think of them as variables if you want.

So, let’s put them in practice. Let’s create a code snippet for inserting dependency properties in our silverlight projects. The code for registering a dependency property with a property changed event handler is the one below:

public bool IsSelected
{
   get { return (bool)GetValue(IsSelectedProperty); }
   set { SetValue(IsSelectedProperty, value); }
}
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(Boolean), typeof(Page), new PropertyMetadata(OnIsSelectedPropertyChanged));
private static void OnIsSelectedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
   Page control = d as Page;
}

As you can see, the property name is used several times as well as the property type, so what we’re gonna do is define a literal for each of them + one literal for the class name. They look like this:

<Snippet>
   <Declarations>
      <Literal>
         <ID>PropertyName</ID>
         <Default>PropertyName</Default>
         <ToolTip>The name of the dependency property.</ToolTip>
      </Literal>
      <Literal>
         <ID>PropertyType</ID>
         <Default>PropertyType</Default>
         <ToolTip>The type of the dependency property.</ToolTip>
      </Literal>
      <Literal>
         <ID>ClassName</ID>
         <Default>ClassName</Default>
         <ToolTip>The name of the owner class.</ToolTip>
      </Literal>
   </Declarations>
</Snippet>

As you can see, each of my literals has three fields: ID – used to identify replaceable portions of code, Default – representing the default value of the literal when the snippet is inserted and ToolTip which is a small description of he literal which shows up at mouse over.

Having these literals set up what we need to next is replace the already defined names and types in our code with literals. This is done by using $ID$ instead of the predefined value (ex: $PropertyName$, $PropertyType$, $ClassName$).

This is how your code should look like inside the snippet after adding the literals:

<Code Language="CSharp">
   <![CDATA[// Defines a DependencyProperty named $PropertyName$ of type $PropertyType$ for the $ClassName$ class.
   public $PropertyType$ $PropertyName$
   {
      get { return ($PropertyType$)GetValue($PropertyName$Property); }
      set { SetValue($PropertyName$Property, value); }
   }
   public static readonly DependencyProperty $PropertyName$Property = DependencyProperty.Register("$PropertyName$", typeof($PropertyType$), typeof($ClassName$), new PropertyMetadata(On$PropertyName$PropertyChanged));
   private static void On$PropertyName$PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   {
      $ClassName$ control = d as $ClassName$;
   }]]>
</Code>

And here is the complete code:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
   <CodeSnippet Format="1.0.0">
      <Header>
         <Title>sldp</Title>
         <Description>Defines a dependency property to use in Silverlight.</Description>
         <Author>StartDebugging.net</Author>
         <Keywords>
            <Keyword>silverlight</Keyword>
            <Keyword>dependencyproperty</Keyword>
         </Keywords>
         <Shortcut>sldp</Shortcut>
         <HelpUrl>http://startdebugging.net</HelpUrl>
      </Header>
      <Snippet>
         <Declarations>
            <Literal>
               <ID>PropertyName</ID>
               <Default>PropertyName</Default>
               <ToolTip>The name of the dependency property.</ToolTip>
            </Literal>
            <Literal>
               <ID>PropertyType</ID>
               <Default>PropertyType</Default>
               <ToolTip>The type of the dependency property.</ToolTip>
            </Literal>
            <Literal>
               <ID>ClassName</ID>
               <Default>ClassName</Default>
               <ToolTip>The name of the owner class.</ToolTip>
            </Literal>
         </Declarations>
         <Code Language="CSharp">
            <![CDATA[// Defines a DependencyProperty named $PropertyName$ of type $PropertyType$ for the $ClassName$ class.
            public $PropertyType$ $PropertyName$
            {
               get { return ($PropertyType$)GetValue($PropertyName$Property); }
               set { SetValue($PropertyName$Property, value); }
            }
            public static readonly DependencyProperty $PropertyName$Property = DependencyProperty.Register("$PropertyName$", typeof($PropertyType$), typeof($ClassName$), new PropertyMetadata(On$PropertyName$PropertyChanged));
            private static void On$PropertyName$PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
               $ClassName$ control = d as $ClassName$;
            }]]>
         </Code>
      </Snippet>
   </CodeSnippet>
</CodeSnippets>



Improve productivity by using code snippets

Code snippets are a great way of improving your productivity because they allow you to define pieces of code which you can later on insert into your projects by using a short alias.

Although they’ve been in Visual Studio for quite some time not many people know what they are, what exactly they do and how to use them in their advantage. Hearing about them is one thing, using them it’s another thing. Almost every one of us (those who write code) used them at least once in our lives and the best example I can think of while saying this is: foreach. I mean, how many times have you typed in foreach and then pressed TAB twice for some code to magically appear at your cursor’s location? Yea, that’s a code snippet! And there is a lot more from where that came from. There are code snippets for things like class definition, constructors, destructors, structures, for, do-while, etc. and a complete list (for C#) can be found here: Visual C# Default Code Snippets.

But those are just a small part of what code snippets can offer, those are the default code snippets that come with Visual Studio. The really nice thing about code snippets is that you can define your own and then use them to insert code in your projects wherever and whenever you want.  I will try and create a simple tutorial on how to create your own code snippet sometime next week, until then you can check out this page.

For those of you looking for a couple of general snippets to add to the already existing one, there’s a nice project on codeplex which contains exactly 38 C# code snippets ready to be added to your collection. Adding them to your Visual Studio is easy: just download the zip file from the link mentioned above and extract the file. Then go to Tools -> Code Snippet Manager or press Ctrl + K, Ctrl + B and click on Import. Browse to the folder where you’ve extracted the zip file, select all the code snippets inside the folder and hit Open, then select which folder / category to add them in (My Code Snippets by default) and click finish. And voila! they are ready to be used. To try them out and see if they really work you can try for example typing task or thread somewhere and hitting TAB twice – your code should be automatically inserted.

So, that’s it for now. As I’ve promised, how to create your own code snippets and maybe also something about some snippet designers coming up next week.




31 Days of Windows Phone Metro Design

Those of you wanting to learn more about metro design and how to make your apps look as metro-ish as possible should know that a new series of articles called “31 Days of Windows Phone Metro Design” has just started.

The first article in the series (about the metro design principles) is already up. A link to the post and to all the upcoming ones can be found here.

Articles will pop up once a week, maybe twice so be sure to check them out.




Leveraging Windows Azure for the Windows Phone Developer – Webinar

Just letting you know that there’s an upcoming webinar on the 4th of this month about Windows Azure and how we can benefit from it in Windows Phone. The webinar will be presented by Samidip Basu and has the following agenda:

  • Introduction to Cloud Computing & Windows Azure
  • Push Notifications for Windows Phone
  • Push Notifications from Azure, including deep-linked secondary Live Tiles & Toasts for Windows Phone Mango
  • Why consider OData while leveraging the cloud in cross-platform Mobile solutions
  • Usage of SQL Azure & OData through Windows Phone
  • Usage of Azure-hosted WCF Services for Windows Phone
  • How to use Azure Toolkit for Windows Phone

Date and time: January 4th at 10 AM PDT (check your local time)
Registration link: https://www1.gotomeeting.com/register/386800777

By tweeting about this webinar using the tag #webinarsilverlightshow you get the chance to win the Windows Phone 7 Silverlight Cookbook and at the end of the webinar by giving a constructive feedback you can also get for free the  OData & Cloud Augmentation of Windows Phone Applications ebook.

For more details about the webinar and the free ebooks feel free to visit SilverlightShow.NET




Transparent TextBox for Windows Phone

Below you have a style which applied to your textbox will make it fully transparent. The difference between applying this style and simply setting the Background property of your textbox to transparent or removing it completely is that the style also removes the focus effect the textbox gets when tapped. I mean no matter what background color you set when the textbox gets focused the background turns white.

So here’s the style (you need to add this to your app/page/user control resources):

<ControlTemplate x:Key="PhoneDisabledTextBoxTemplate" TargetType="TextBox">
	<ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/>
</ControlTemplate>
<Style x:Key="TransparentTextBoxStyle" TargetType="TextBox">
	<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
	<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
	<Setter Property="Background" Value="{StaticResource PhoneTextBoxBrush}"/>
	<Setter Property="Foreground" Value="{StaticResource PhoneTextBoxForegroundBrush}"/>
	<Setter Property="BorderBrush" Value="{StaticResource PhoneTextBoxBrush}"/>
	<Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/>
	<Setter Property="SelectionForeground" Value="{StaticResource PhoneTextBoxSelectionForegroundBrush}"/>
	<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
	<Setter Property="Padding" Value="2"/>
	<Setter Property="Template">
		<Setter.Value>
			<ControlTemplate TargetType="TextBox">
				<Grid Background="Transparent">
					<VisualStateManager.VisualStateGroups>
						<VisualStateGroup x:Name="CommonStates">
							<VisualState x:Name="Normal"/>
							<VisualState x:Name="MouseOver"/>
							<VisualState x:Name="Disabled">
								<Storyboard>
									<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="EnabledBorder">
										<DiscreteObjectKeyFrame KeyTime="0">
											<DiscreteObjectKeyFrame.Value>
												<Visibility>Collapsed</Visibility>
											</DiscreteObjectKeyFrame.Value>
										</DiscreteObjectKeyFrame>
									</ObjectAnimationUsingKeyFrames>
									<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DisabledOrReadonlyBorder">
										<DiscreteObjectKeyFrame KeyTime="0">
											<DiscreteObjectKeyFrame.Value>
												<Visibility>Visible</Visibility>
											</DiscreteObjectKeyFrame.Value>
										</DiscreteObjectKeyFrame>
									</ObjectAnimationUsingKeyFrames>
								</Storyboard>
							</VisualState>
							<VisualState x:Name="ReadOnly">
								<Storyboard>
									<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="EnabledBorder">
										<DiscreteObjectKeyFrame KeyTime="0">
											<DiscreteObjectKeyFrame.Value>
												<Visibility>Collapsed</Visibility>
											</DiscreteObjectKeyFrame.Value>
										</DiscreteObjectKeyFrame>
									</ObjectAnimationUsingKeyFrames>
									<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DisabledOrReadonlyBorder">
										<DiscreteObjectKeyFrame KeyTime="0">
											<DiscreteObjectKeyFrame.Value>
												<Visibility>Visible</Visibility>
											</DiscreteObjectKeyFrame.Value>
										</DiscreteObjectKeyFrame>
									</ObjectAnimationUsingKeyFrames>
									<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="DisabledOrReadonlyContent">
										<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneTextBoxReadOnlyBrush}"/>
									</ObjectAnimationUsingKeyFrames>
								</Storyboard>
							</VisualState>
						</VisualStateGroup>
						<VisualStateGroup x:Name="FocusStates">
							<VisualState x:Name="Focused"/>
							<VisualState x:Name="Unfocused"/>
						</VisualStateGroup>
						<VisualStateGroup x:Name="ValidationStates">
							<VisualState x:Name="InvalidFocused"/>
							<VisualState x:Name="Valid"/>
							<VisualState x:Name="InvalidUnfocused"/>
						</VisualStateGroup>
					</VisualStateManager.VisualStateGroups>
					<Border x:Name="EnabledBorder" BorderThickness="{TemplateBinding BorderThickness}" Margin="{StaticResource PhoneTouchTargetOverhang}">
						<ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" Margin="{StaticResource PhoneTextBoxInnerMargin}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="Stretch"/>
					</Border>
					<Border x:Name="DisabledOrReadonlyBorder" BorderThickness="{TemplateBinding BorderThickness}" Margin="{StaticResource PhoneTouchTargetOverhang}" Visibility="Collapsed">
						<TextBox x:Name="DisabledOrReadonlyContent" Foreground="{StaticResource PhoneDisabledBrush}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" IsReadOnly="True" SelectionForeground="{TemplateBinding SelectionForeground}" SelectionBackground="{TemplateBinding SelectionBackground}" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" Text="{TemplateBinding Text}" Template="{StaticResource PhoneDisabledTextBoxTemplate}"/>
					</Border>
				</Grid>
			</ControlTemplate>
		</Setter.Value>
	</Setter>
</Style>

Now that you’ve got the style, all you need to do is apply it to your textbox like so:

<TextBox Style="{StaticResource TransparentTextBoxStyle}"/>

And that’s all. Your textbox should be 100% transparent now. Also, in case you want to try it out before using it I’ve made a sample project you can download below.

Download Transparent TextBox Sample




Expression Blend 4 has stopped working? Here’s your FIX.

Okay, so this happened to me twice already and in both cases it stopped working after installing the Visual Studio 11 Dev Preview. Having already two PCs on which Expression Blend stopped working I decided to do a little bit of digging and fortunately for me it really took just a bit. The crash is actually a known issue caused by the installation of .NET Framework 4.5 or Visual Studio 11 Dev Preview and the solution for it is rather simple and only takes a couple of minutes.

So what you need to do is open up a command prompt window with administrative privileges and run the commands listed below. Those of you running 32-bit operating systems use %ProgramFiles% instead of %ProgramFiles(x86)%.

C:\> %windir%\Microsoft.NET\Framework\v4.0.30319\ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Framework.dll"

C:\> %windir%\Microsoft.NET\Framework\v4.0.30319\ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Blend.dll"

C:\> %windir%\Microsoft.NET\Framework\v4.0.30319\ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.Project.dll"

 

If your Expression Blend has Service Pack 1 you’ll need to run this command a well:

C:\> %windir%\Microsoft.NET\Framework\v4.0.30319\ngen uninstall "%ProgramFiles(x86)%\Microsoft Expression\Blend 4\Microsoft.Expression.WindowsPhone.dll"