Tuesday, July 13, 2010

Bing Videos… Are you Kidding Me?!?!?!?

So there is nothing technical about this post, but I found it interesting. I have been a big supporter of Microsoft Silverlight, but I do find it a bit frustrating when I find out they don’t use their own technologies internally. Check this post out, it points out how Microsoft uses Flash for their Bing videos rather than Silverlight!

image

Now, when you click on the video, you are taken to a Silverlight player where you can view the entire clip, but why the use of Flash for the preview? Why not Silverlight? What was the technical challenge that caused them to go with Flash?

http://geekygab.blogspot.com/2010/07/bing-videos-are-you-kidding-me.html

 

Friday, July 2, 2010

Get Local Time Zone

Here’s a quick post on how to get the local time zone in your Silverlight Applications. You need to use the System.TimeZoneInfo class to get this information. This simple call will give you your local time zone.

TimeZoneInfo.Local.StandardName



If you have a DateTime value you want to convert to local time, just call the ToLocalTime method on it and that should do it. You can also use the ToUniversalTime method on it to convert it to UTC time.



Thursday, June 17, 2010

Snippet Designer

I am a big proponent of code snippets. I use them all the time and I tend to write my own snippets for code I write over and over. Recently, I found a nice Visual Studio extension out in codeplex that lets you write your own code snippets a bit faster than editing the xml yourself. Although it isn’t very difficult, I have found this new method of writing snippets a bit faster, so I thought I would blog about it. If you are interested in trying this out, here is the url: http://snippetdesigner.codeplex.com/

The extension takes no time to install. once you have it installed, all you do is select the code you want to be created as a snippet and right click and export it as a snippet. From there, you open up a nice designer that lets you change the details of your snippet and create Replacements. It is a very cool tool and once you play around with it for a while, you’ll be creating snippets in no time and well on your way to saving time in your coding.

image

image

Enjoy!

Tuesday, May 11, 2010

Another Strange Silverlight Error: “Layout cycle detected. Layout could not complete”

Wow! Is this one ever frustrating! So here’s the situation:

I’ve got a datagrid which uses RowGroups. Everything is working just fine until I get a request from the product owner to hide/show several of the columns on that datagrid by clicking a button. I figured “This isn’t going to be too bad. I’ve done this before with other datagrids. Great, I’ll have it done in 10 minutes.” WRONG! To my surprise, I wrote some code very similar to what I’ve done in the past, but I started seeing this funky error “Layout cycle detected. Layout could not complete”. Because this is a Silverlight error, I did not get any other helpful information. Thanks so much Silverlight. Well, I can’t tell you that I completely understand the internals of Silverlight and what is causing this issue, but I do know that it has something to do with looping inside the the UpdateLayout method is executing for the datagrid. It seems to be getting stuck in an infinite loop. After a lot of searching and trying out different things, I came up with a workaround. If you are experiencing this problem, try removing the datagrid from its parent prior to making the change (in my case adding/removing columns) and then add the datagrid back to it’s parent’s Children collection immediately after you make the change.

This solved it for me. Here is a snippet:

            if (show == true)
{
_clmOne.Visibility = Visibility.Visible;
_clmTwo.Visibility = Visibility.Visible;
_clmThree.Visibility = Visibility.Visible;
}
else
{
//Hack:Need to remove the grid prior to adding columns to avoid Exception.
this.LayoutRoot.Children.Remove(myDataGrid);
_clmOne.Visibility = Visibility.Collapsed;
_clmTwo.Visibility = Visibility.Collapsed;
_clmThree.Visibility = Visibility.Collapsed;
this.LayoutRoot.Children.Add(myDataGrid);
}


I hope this helps you guys out. Happy Silverlighting!


Wednesday, April 28, 2010

Are You Annoyed With The Visual Studio XAML Design View?

I know I was! Sure, Visual Studio 2010 has a much improved designer (especially if you are working with Silverlight), but for the most part, the designer for Silverlight and WPF applications is pretty weak. I would much rather work in Blend or straight XAML. If I had to edit a XAML page in Visual Studio, I would always open the file and immediately switch to full XAML view. The designer always took too long to load and it wasted a lot of my time. Well, if you are in the same boat, here is a little tip. You can configure Visual Studio to always open XAML files in full XAML view and bypass the designer. To do this, go to the Tools menu and select Options. In the options dialog, select the Text Editor element on the left hand side and go to XAML and the Miscellaneous. Under the Default View section, make sure the ‘Always open documents in Full XAML view’ is checked and click ok. That should do it. From now on you will open your XAML files directly in the XAML view and you won’t have to wait for the editor to load and tell you it can’t render the XAML.

image

Note: The version of VS I am running is VS 2010 Ultimate.

Thursday, April 15, 2010

Silverlight 4 Just Released – Books to Help You Out

 

With the release of Sivlerlight 4 and all the tools related to that technology, now is a great time to learn how to develop rich web applications using Microsoft Silverlight. This knowledge will also allow you to create rich applications for the upcoming Windows Phone 7 devices. Follow the links below to purchase some of the newest (most up to date) books on Silverlight development.

  

 

Friday, March 26, 2010

How to use Isolated Storage on Windows Phone 7

 

image

I wrote a little sample application that lets the user work with the isolated storage on a Windows Phone 7 device. I won’t bother you with the details of the xaml because the UI is relatively straight forward. There are only a handful of controls and they are all pretty standard. What I want to share here is the code behind that makes this application work. Besides, it’s not really the most amazing app out there, it’s just meant to show you how to work with ISO storage.

The key take-aways from this are:

1) You will need to add reference to the System.IO.IsolatedStorage assembly and add the corresponding using statement.

2) You save and retrieve the settings by calling IsolatedStorageSettings.ApplicationSettings

3) You access the setting values via their keys - IsolatedStorageSettings.ApplicationSettings[“key”]= “value”;

Hopefully this gets you started saving and retrieving data to and from a Windows Phone 7 device.

More to come… happy coding!

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.IO;

namespace Isolated_Storage
{
public partial class MainPage : PhoneApplicationPage
{
private IsolatedStorageSettings appSettings;

public MainPage()
{
InitializeComponent();

SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;

btnAdd.Click += new RoutedEventHandler(btnAdd_Click);
btnRead.Click += new RoutedEventHandler(btnRead_Click);
txtValue.TextChanged += new TextChangedEventHandler(txtValue_TextChanged);

appSettings = IsolatedStorageSettings.ApplicationSettings;

UpdateSettingsCount();
}

private void UpdateSettingsCount()
{
lblCount.Text = String.Format("App Settings Count: {0}", appSettings.Count);
}

void txtValue_TextChanged(object sender, TextChangedEventArgs e)
{
btnAdd.IsEnabled = txtValue.Text.Trim().Length > 0;
}

void btnRead_Click(object sender, RoutedEventArgs e)
{
lstItems.Items.Clear();
LoadData();
}

void btnAdd_Click(object sender, RoutedEventArgs e)
{
IsolatedStorageSettings.ApplicationSettings[(appSettings.Count + 1).ToString()] = txtValue.Text;
UpdateSettingsCount();
}

private void LoadData()
{
for (int i = 0; i < appSettings.Count; i++)
{
string entry = string.Format("Key: {0} {1}Value: {2}", i + 1, Environment.NewLine, appSettings[(i + 1).ToString()].ToString());
lstItems.Items.Add(entry);
}
}
}
}