Phone7ActionPack Sample 3 – Let there Bing Maps
So location controls are nice but I am sure that you would rather be able to show your users a map rather than just say here is a your Latitude & Longitude. This sample also talks about some of the other stuff that will be included with the release that isn't visual.
Presentation for Lambda Expressions
So I gave this talk about Lambda Expressions in C# today and people seemed to like it... In fact it was standing room only and the event organizer asked me to do a repeat this afternoon at the 2:30pm time slot. For all those that are interested here is the presentation that I gave as well as the VS2010 project sample
Silverlight Temp File Issue
I don't know how well known this issue is with Silverlight or exactly what versions that it effects I saw a few form posts about it. But my company has several applications written in Silverlight that use Web Services and it affects all of them. When Silverlight calls a web service it seems to create a temp file of exactly 20,971,520 bytes (exactly 20MB) each time . This is not a big deal if you call a web service only once or even ten times for that matter but when you have your app set to call it every 10 seconds at this rate you application will require 120MB per minute of hard disk space to continue running. It seems that when you reload the page the temp files are cleared but if you want the app to run for weeks on end to drive a display for example you have to manually force them to be cleared out. The files will be created in the %temp% folder and will follow a naming convention of XCP*.tmp (XCP833C.tmp, XCP6FAB.tmp, ect)
This is not so much a bug as something that you need to keep in mind when your using Silverlight to constantly refresh data from the server.
The fix for this is as follows:
If you just put that one line of code at the end of your Async Completed handler and all you massive hard drive usage issues will be a thing of the past.
It should also be noted that I can't recreate this issue when the app is running off the development server built into Visual Studio. It seems to only have this issue once I publish to IIS.
Pivot Collection Maker
Computer Guy and I have been exchanging emails for a few weeks about Pivot and how to move forward with releasing a new tool to the general .Net community to make Pivot easy to work with. And thanks to a lot of hard work by Guy we now have the Pivot Collection Maker. Check out the source which is very well documented for the updated Pivot Collection Tools that is now using XmlWriter and classes based off the XSD files from the Pivot Team.
Pivot Collection SDK (Beta) Release
I have just posted the first fully functional Pivot Collection Tools release over at CodePlex. This tool provides a great deal of automation. All you need to do on your end is mark your class with the attributes as demonstrated in the sample app provided. Then, populate a List and tell the tool to start building.
That’s right, it really is that simple!
Facebook Collection Builder – Independent Demo
Manan from beingmanan.com was treated an early preview of my Collection Builder Tool. He was kind enough to put together an informative post about the app. If you would like to see Facebook Friends Collection in action, feel free to check out Manan's post, which also contains a video of the app in action.
Facebook Friends Live Collection
Yesterday, I presented you with a demo video of my Facebook Friends Collection for Pivot. Today, I have a live collection for you to play with. (Please note that Pivot is required)
Improved Facebook Friend Demo (I can't seem to get it to run on IIS as GoDaddy has it configured. This is most likely due to the inability to add MIME types. On the plus side, kudos to the Pivot team for this, as it makes it so a LAMP environment can easily serve it up.)
To make the application work, I have developed an easy-to-use method for turning almost any class in to a collection. This method was utilized in the example below, which shows the inner workings of Facebook Friends.
{
private List _books = new List();
private List _activities= new List();
private List _interests = new List();
private List _movies= new List();
private List _music = new List();
private List _tv= new List();
[PivotItem(IsName = true)]
public string Name { get; set; }
[PivotItem(IsDescription = true)]
public string Desc { get; set; }
[PivotItem(FacetDisplayName = "Books", FacetType = FacetTypes.String, IsFacet = true,IsCollection = true)]
public List Books
{
get { return _books; }
set { _books = value; }
}
[PivotItem( IsImage = true)]
public string Image { get; set; }
[PivotItem(FacetDisplayName = "Gender", FacetType = FacetTypes.String, IsFacet = true)]
public string Sex { get; set; }
[PivotItem(FacetDisplayName = "Relationship Status", FacetType = FacetTypes.String, IsFacet = true)]
public string RelationshipStatus { get; set; }
[PivotItem(FacetDisplayName = "Political Views", FacetType = FacetTypes.String, IsFacet = true)]
public string PoliticalViews { get; set; }
[PivotItem(FacetDisplayName = "Birth Date", FacetType = FacetTypes.String, IsFacet = true)]
public string BirthDate { get; set; }
[PivotItem(FacetDisplayName = "Activities", FacetType = FacetTypes.String, IsFacet = true, IsCollection = true)]
public List Activities
{
get { return _activities; }
set { _activities = value; }
}
[PivotItem(FacetDisplayName = "TV Shows", FacetType = FacetTypes.String, IsFacet = true, IsCollection = true)]
public List Tv
{
get { return _tv; }
set { _tv = value; }
}
[PivotItem(FacetDisplayName = "Music", FacetType = FacetTypes.String, IsFacet = true, IsCollection = true)]
public List Music
{
get { return _music; }
set { _music = value; }
}
[PivotItem(FacetDisplayName = "Movies", FacetType = FacetTypes.String, IsFacet = true, IsCollection = true)]
public List Movies
{
get { return _movies; }
set { _movies = value; }
}
[PivotItem(FacetDisplayName = "Intrests", FacetType = FacetTypes.String, IsFacet = true, IsCollection = true)]
public List Interests
{
get { return _interests; }
set { _interests = value; }
}
}
In order to populate the collection, I do something like this:
<span>// </span>In this space, there are about forty (40) lines of code that pull the data out of the Facebook API from CodePlex
<span>// and put it in to an instance of the above class. Then I add the data to the collection as follows:</span>
friends.Items.Add(facebookUserInstance);
friends.CollectionName = "Facebook Friends";
friends.WriteCollectionToFileSystem("test1.cxml");
<span>// </span><span>Next, I run the two command line tools for converting my friends' pictures into deep-zoom images and voila! It is done!</span>
I will be posting the Project for how the above works once the source code is cleaned up a bit and I am able to provide better documentation.
If you would like a copy of it before then, feel free to ask. I would be happy to send it to you if you post a comment requesting it.
Pivot – Facebook Friends
Today, I finished up a simple example of what you can do with Pivot from Microsoft's Live Labs. The concept is simple: Using the powerful data visualization tool that is Pivot, it is possible to visualize the wide range of information that Facebook tracks about all of its users and what is available to you regarding your Facebook friends. This demo is just the tip of the iceberg. Currently, it displays your friends’ places of employment, colleges, sex, wall post counts, “About Me,” name, profile picture, and birth date. I intend to have this app display much more information. I will be working on it over the next week or so in order to expand its potential.
Simple Tree Part 1
For those of you that have been enjoying some of the features in the Silverlight Toolkit over on codeplex like I have been you may have noticed the same things that I have about it. First it works but thats a given after all its made by the same company that brought you Songsmith, and since its from Microsoft you know its easy to use.
But other than that it does way more with visual states then the average developer can probably understand given our limited understanding of the ever so complicated art of making things look pretty. More over it works like a champ if you want to use it with a limited number of levels of depth but as far as I can see with out looking at source for it there is no way for it to automatically go to the n level of depth on its own. So for us data driven guys it wets the appetite but leaves us feeling totally unsatisfied much like running any version of 7 other than Ultimate.
I would like to present a simple solution to give those of you looking for a simple solution to avoid defining a template for each level of depth in you tree. This post is part 1 of a hopeful 3 part look at how to make a slick DynamicTreeView. In part 1 I'll show you how to make the basic tree saving the styling for part 2. In part 3 we will roll the entire thing in to nice reusable UserControl that allows you easily make this fit into your application.
For this demo go ahead an make yourself a new Silverlight Application or Silverlight Class Library in Visual Studio 2008 either will do. I am going to use Silverlight Application so that I can just hit F5 to preview at any time but the Solution that I'll post with this will be a Silverlight Class Library. Now go ahead and make 2 User Controls AutoNode.xaml and DynamicTreeView.xaml. AutoNode is where all the magic happens and DynamicTreeView is the finished product that will work like the current TreeView in the Silverlight Toolkit.
At this point you should have a solution similar to the one on the left.
Lets start with DynamicTreeView.xaml and put an ItemsControl in LayoutRoot like this.
x:Class="SilverlightApplication1.DynamicTreeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="400">
<Grid x:Name="LayoutRoot" Background="Black">
<ItemsControl />
</Grid>
</UserControl>
Go ahead an build you solution so that everything will be ready to work with Blend when we open it.
For those of you with Expression Blend Lets right click on the DynamicTreeView.xaml in our Solution Explorer and open it with Expression Blend (you can do this with out Expression Blend but for god sakes use Expression Blend cause you don't get extra points for doing it the hard way) on the Objects and Timelines area lets right click on our ItemsControl then go to
Edit Additional Templates -> Edit Generated Items Template (ItemTemplate) -> Create Empty
like shown below.


This is creating the template that will house all of the top level tree items for our tree view. You'll be presented with the dialog shown above enter the name you want to call this template I am using RootTreeViewItem. Once you click ok you will be presented with a empty template that has a grid and nothing else. At the far left toolbar select the assets icon and type "auto", you should be able to select the AutoNode UserControl and add it to the grid and clear any attributes for the AutoNode in the XAML.

At this point your XAML should now have a pretty simple data template added to it like the following
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightApplication1" x:Class="SilverlightApplication1.DynamicTreeView"
Width="200" Height="400">
<UserControl.Resources>
<DataTemplate x:Key="RootTreeViewItem">
<Grid>
<local:AutoNode/>
</Grid>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Black">
<ItemsControl ItemTemplate="{StaticResource RootTreeViewItem}" />
</Grid>
</UserControl>
OK next up lets open up AutoNode.xaml and finish the basic function of this tutorial. I am not going to go over the details of the layout as teaching basics of layouts in Silverlight is beyond the scope of this tutorial so lets use this XAML. Interesting note I was seemingly unable to add a instance of AutoNode to a template that lived on AutoNode using drag and drop with Expression Blend (guessing that this is a safe guard against accidental recursion. If anyone can confirm this I would appreciate it.)
x:Class="SilverlightApplication1.AutoNode"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="273"
d:DesignHeight="87"
VerticalContentAlignment="Top">
<UserControl.Resources>
<DataTemplate x:Key="Children">
<auto:AutoNode VerticalAlignment="Top" />
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="21"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" />
<ItemsControl Grid.Column="1" Grid.Row="1" ItemTemplate="{StaticResource Children}" />
</Grid>
</UserControl>
But the above is somewhat simular to one of the templates used for the TreeViewItem in the Silverlight Toolkit. With just a little bit of data binding this will populate a Tree of nodes that conforms to the same convention for each level with no limit of depth. (short of running out of memory in theory)
I used the following Simple class that would mimic a file system recursive directory listing. If your running a x64 system the paths used should map to real paths on your system. The FileNode class is intended to eventually provide the needed data so that this tree view by the end of part 3 will be able to visually identify if a node is a file or a directory with a different icon.
{
public string DisplayValue { get; set; }
public string Path { get; set; }
public bool IsFolder { get; set; }
private ObservableCollection _children = new ObservableCollection();
public ObservableCollection Children
{
get { return _children; }
set { _children = value; }
}
public FileNode() {}
}
public class FileSystemHelper
{
private ObservableCollection nodes = new ObservableCollection();
public FileSystemHelper()
{
Nodes.Add(new FileNode()
{
DisplayValue = "Windows",
Path = "C:\\Windows",
IsFolder = true
});
Nodes[0].Children.Add(new FileNode()
{
DisplayValue = "Microsoft.NET",
Path = "C:\\Windows\\Microsoft.NET",
IsFolder = true
});
Nodes[0].Children[0].Children.Add(new FileNode()
{
DisplayValue = "Framework64",
Path = "C:\\Windows\\Microsoft.NET\\Framework64",
IsFolder = true
});
Nodes[0].Children[0].Children.Add(new FileNode()
{
DisplayValue = "Framework",
Path = "C:\\Windows\\Microsoft.NET\\Framework",
IsFolder = true
});
Nodes[0].Children[0].Children[0].Children.Add(new FileNode()
{
DisplayValue = "v3.5",
Path = "C:\\Windows\\Microsoft.NET\\Framework64\\v3.5",
IsFolder = true
});
Nodes[0].Children[0].Children[0].Children.Add(new FileNode()
{
DisplayValue = "sbscmp10.dll",
Path = "C:\\Windows\\Microsoft.NET\\Framework64\\v3.5\\sbscmp10.dll",
IsFolder = false
});
Nodes[0].Children[0].Children[0].Children.Add(new FileNode()
{
DisplayValue = "sbscmp20_mscorwks.dll",
Path = "C:\\Windows\\Microsoft.NET\\Framework64\\v3.5\\sbscmp20_mscorwks.dll",
IsFolder = false
});
}
public ObservableCollection<FileNode> Nodes
{
get { return nodes; }
set { nodes = value; }
}
}
}
Currently we only care about the DisplayValue, Path, and Children properties so lets go ahead and add the data binding to AutoNode.xaml. Change the TextBlock and the ItemsControl to the following
<ItemsControl Grid.Column="1" Grid.Row="1" ItemTemplate="{StaticResource Children}" ItemsSource="{Binding Children}"/>
The Last step that we need to add a data context to the grid on DynamicTreeView.xaml and set an ItemsSource binding for the ItemsControl below is what the final DynamicTreeView.xaml should look like.
x:Class="SilverlightApplication1.DynamicTreeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightApplication1"
Width="300" Height="400">
<UserControl.Resources>
<DataTemplate x:Key="RootTreeViewItem">
<Grid>
<local:AutoNode/>
</Grid>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Black">
<Grid.DataContext>
<local:FileSystemHelper/>
</Grid.DataContext>
<ItemsControl ItemTemplate="{StaticResource RootTreeViewItem}" ItemsSource="{Binding Nodes}" />
</Grid>
</UserControl>
Lets not forget to add the DynamicTreeView to the MainPage.xaml so it shows up when we hit preview.
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SilverlightApplication1"
x:Class="SilverlightApplication1.MainPage"
Foreground="White">
<Grid HorizontalAlignment="Left" VerticalAlignment="Top">
<local:DynamicTreeView />
</Grid>
</UserControl>

To the left you can see that we currently have a stunningly bland proof of concept for our recursive TreeView. Its worth noting that there is not one line of programmatic code that is making this happen (other than the code to generate the items to display but with some work you can make the AutoNode use reflection to check to see if its DataContext has any property that implements ICollection/IList/IEnumerable and if so try to map that to the children field.)
Now you must be thinking OK but what can I do with this? Well I was thinking that myself after this was done and so here is an example of what to do with it. With a few changes to the code we had that defined the FileSystemHelper and FileNode classes we can make VisualFamilyTree and FrameworkElementNode classes as below.
/// Modified from FileSystemHelper
/// </summary>
public class VisualFamilyTree
{
private ObservableCollection<FrameworkElementNode> nodes = new ObservableCollection<FrameworkElementNode>();
public VisualFamilyTree() {}
/// <summary>
/// This method will be called after the rootElement has fully loaded and is ready to be transversed
/// </summary>
/// <param name="rootElement"></param>
public void Populate(FrameworkElement rootElement)
{
Nodes.Clear(); // this is done to make the tree only ever have one node
Nodes.Add(new FrameworkElementNode(rootElement));
}
public ObservableCollection<FrameworkElementNode> Nodes
{
get { return nodes; }
}
}
/// <summary>
/// Modified from FileNode
/// </summary>
public class FrameworkElementNode
{
public string DisplayValue { get; set; }
public string Path { get; set; }
private ObservableCollection<FrameworkElementNode> _children = new ObservableCollection<FrameworkElementNode>();
public ObservableCollection<FrameworkElementNode> Children
{
get { return _children; }
set { _children = value; }
}
public FrameworkElementNode() { }
/// <summary>
/// constructor that auto builds off of a FrameworkElement
/// </summary>
public FrameworkElementNode(FrameworkElement fe)
{
// how many child nodes does this element have that are direct children of this FrameworkElement
int childNodes = VisualTreeHelper.GetChildrenCount(fe);
if(childNodes> 0)
for (int i = 0; i < childNodes; i++)
{
// recursively call this for each FrameworkElement that is a child element of the FrameworkElement fe
Children.Add(new FrameworkElementNode(VisualTreeHelper.GetChild(fe, i) as FrameworkElement));
}
// using path for name so we didn't have to make any changes to the AutoNode.xaml
Path = fe.Name;
// the node "header" will be x:Name ( type of this FrameworkElement )
DisplayValue = Path+ "( " + fe.GetType().Name + " )";
}
}
The goal of this is to make our recursive TreeView build in real time from the live code that is running in browser to give us the same kind visual tree that we have in Expression Blend at design time. Looking below you can see a quick collection of controls that I threw on a page. A quick search didn't bring up anyone doing anything like this in real time running in Silverlight. The closest that I could find to doing something like this was Silverlight Spy. Granted currently it only looks for simple parent child relationships and wont peek into templates of any kind (though that should be pretty straight forward to implement) on the other hand the code to make the live tree only took like 10 min so its a fair trade I guess.
Now here is a screen shot of it running live in Silverlight and note that the tree is the same.

Download the full solution for Here.
Application Name in .net Connection Strings
Ever want to check to see how data got into your database? I know that at times I will fire up SQL Managment Studio and make some changes when I need to we all do it. Here is a nice little trick that you can put in a trigger on sensitive tables to record what application told the database to update/insert. the below will yield you what ever value you put in the Application Name parameter in the connection string. I got in the habit of auto appending this to the connection strings stored in my app.config and web.config files in compiled code so that if I need to I can see what program is connecting and with what credentials.
Go ahead load up SQL Server Managment Studio and run that query you should get "Microsoft SQL Server Management Studio - Query"







































