Currently DateTime.ToShortDateString will not include any "0" prefixes. I think this makes any vertical lists of dates look funky:
Here is a very simple
extension method that will append any needed leading "0" to the date:
namespace ParaPlan.Extensions
{
public static class DateHelper
{
public static string ToShortDateEqualLengthString(this DateTime dt)
{
var rv = new StringBuilder();
if (dt.Month.ToString().Length ==1)
{
rv.Append("0");
}
rv.Append(dt.Month.ToString());
rv.Append("/");
if (dt.Day.ToString().Length == 1)
{
rv.Append("0");
}
rv.Append(dt.Day.ToString());
rv.Append("/");
rv.Append(dt.Year.ToString());
return rv.ToString();
}
}
}
Changing our dates to call .ToShortDateEqualLengthString will make our listbox look much more pretty:
Al Pascual has been working on
GeoTwitter, a website (
open source on CodePlex) that add geographical context to your tweets. That is pretty cool and he is looking at ways to automate it (IP, cell GPS), but what I think is really cool is that he provides a GeoRSS feed of your tweets (with others).
Check out the site here. He posts about the project, submitting it to open source and future ideas
on his blog.
Using the CollectionViewSource is a good way of binding to a datasource and letting the XAML determine the sorting and grouping of the data. However, as your datasource changes, the grouping and sorting is not automatically "re-calculated", forcing your code to be smarter that it should be. I found a
class today on MSDN forums that inherits from CollectionViewSource and adds automatic refresh capabilities. This code is smart enough to resort your items, regroup your items and even add new groupings as needed.
Some good CollectionViewSource links:
I don't think the WPF ToogleButton has a distinct visual difference between it's checked and unchecked state. So I wanted to change the text displayed when the button was checked. So I created a trigger that looked at the IsChecked property and changed the content property accordingly. However, the default template of a ToggleButton changes it's appearance when it is checked, so certain properties are not written as expected. To fix this, I set the content property in the styles of the toggle button and it worked. Here is the code:
<ToggleButton Name="showStopsCheckBox">
<ToggleButton.Style>
<Style TargetType="{x:Type ToggleButton}">
<Setter Property="Content" Value="Stops"/>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Content" Value="Trips"/>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
Here is how to post to
GeeksWithBlogs from
Google Docs.
- Click New -> Document
- Select "Publish as web page" from the Share menu
- Click setup your blog
- Select "My own server/custom"
- Select "MetaWeblog API" from the drop down list
- Enter (no www) http://geekswithblogs.net//services/metablogapi.aspx
- Populate your user name, password and blog title
- Click Test
I just finished my presentation about consuming Google Maps at
BarCampKC. Thanks to everybody who attended.
We talked about the three different ways of using Google Maps in your applications or websites.
- Static Map Image API
- My Maps
- JavaScript API
The slideshow is available
via Google Docs or
dowload the PPT
The code is available
for download here, make sure you
change your api key.
Chelsea and I went to the movies last night and saw Todd Reesing (the KU quarterback) and Derek Fine (former KU tight end) standing in line at the ticket counter. Turns out they went to the same movie as us too (Baby Mama - which was pretty funny).
I fixed the error I posted about yesterday. I updated the post to say:
Update: I had also uninstalled VS 2008 Team Suite trial, when I went to install VS 2008 For Developers, I didn't have enough space, which is why I had uninstalled VS 2005 in the first place. I freed up some space and installed VS 2008 and now all is working.
Technorati tags:
TeamBuild,
MSB3147
All of our projects that use TeamBuild are now being built with Visual Studio 2008, so to free up some much needed space on our server, I uninstalled Visual Studio 2005. Now all our builds are failing with the message:
error MSB3147: Could not find required file 'setup.bin' in 'e:\b\Goldstar\gs_main\Sources\main\source\code\ParaPlan\ParaPlanWPF\Engine'.
I found a thread on MSDN that suggested reinstalling the .NET SDK, so I'm trying that.
Update: I had also uninstalled VS 2008 Team Suite trial, when I went to install VS 2008 For Developers, I didn't have enough space, which is why I had uninstalled VS 2005 in the first place. I freed up some space and installed VS 2008 and now all is working.
Let's say you have a custom WPF control called SearchTextBox. It has a textbox and a button labeled "search". Simple enough, you reuse it in your application when you want to provide search.
Then one day, you decide you need this control needs to be bindable. So you expose a public property Text and map it to textSearch just like you would in WinForms.
Well, that doesn't work, so you google around and stumble upon Dependency Properties and learn how to create your own (VS snippet shortcut propdb) and create a Text DP.
Now you spend 30 minutes trying to map your Text DP to your textSearch.Text until you finally figure out that your DP snippet lead you astray and there is one more step that didn't get included in the shortcut. In the UIPropertyMetaData, you need to specify a function to call when the property changes - so you can set textSearch.Text.
The function looks like this:
static void textChangedCallBack(DependencyObject property,
DependencyPropertyChangedEventArgs args)
{
SearchTextBox searchTextBox = (SearchTextBox)property;
searchTextBox.textSearch.Text= (string)args.NewValue;
}
And the rest of the DP looks like this:
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register(
"Text",
typeof(string),
typeof(SearchTextBox),
new UIPropertyMetadata(string.Empty, new PropertyChangedCallback(textChangedCallBack)));
The important part here is what wasn't created by the VS snippet :
new UIPropertyMetadata(string.Empty, new PropertyChangedCallback(textChangedCallBack))
Now you are binding to your custom control and all is good.
I keep getting this error in Visual Studio 2008 on Vista:

I'm not sure what the issue is, but if you get this error, just stop the VSPerfMon.exe process and you can continue testing without rebooting your computer.
I had some trouble today getting the actual control that hosts data in a WPF listbox. The magic class is ListBox.ItemContainerGenerator used like this:
MyStateObject current = this.myListBox.SelectedItem as MyStateObject;
ListBoxItem lbi = this.myListBox.ItemContainerGenerator.ContainerFromItem(current) as ListBoxItem;
lbi.Margin = new Thickness(10);
For those of us that implement INotifyPropertyChanged on our state objects, the new Automatic Properties feature of Visual Studio 2008 hasn't been very useful. In fact, the snippet prop that used to create a private variable and associated public property has now been replaced by an Automatic Property.
Thanks to a comment by SnYnE on this blog post, there is an easy way to get the functionality back.
Simply create a new text file at:
C:\users\*your user name*\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets
Call it "propc.snippet"
Populate the contents with:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>prop</Title>
<Shortcut>propc</Shortcut>
<Description>Code snippet for property and backing field</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>Property type</ToolTip>
<Default>int</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip>Property name</ToolTip>
<Default>MyProperty</Default>
</Literal>
<Literal>
<ID>field</ID>
<ToolTip>The variable backing this property</ToolTip>
<Default>myVar</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[private $type$ $field$;
public $type$ $property$
{
get { return $field$;}
set { $field$ = value;}
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Now when you type "propc" in Visual Studio, you will get the property constructor that you are used to.
Yahoo Live launched last night. It is basically a social network of webcams. They talk more about it on their blog.
Once I saw it on digg this morning, I configured my "live" in about 20 seconds. It automatically pickup my webcam and started broadcasting. My page is here, I doubt I'll keep it up, but it's fun to play with and it fits perfectly with my exhibitionism :) They allow you embed your webcam, so I'm going to try that here:
This very simple extension method makes a string a fixed length. It appends whitespace to a string that is shorter than required or strips characters to a string to is longer than requested.
See ScottGu blog post for a brush up (or intro) on extension methods.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ParaPlan.Extensions
{
public static class StringHelper
{
public static string ToFixedLength(this string s, int width)
{
string rv = s;
if (s.Length > width)
{
rv = s.Remove(width);
}
else
{
int neededWhiteSpace = width - s.Length;
rv = s + new string(char.Parse(" "), neededWhiteSpace);
}
return rv;
}
}
}

After a couple years of dating and exactly one year of living together, Chelsea and I got engaged yesterday. We are planning a small beach wedding off the North Carolina coast in March 2008. She's always wanted a beach wedding, and well, that's all that counts. Plus we found this really cool self proclaimed hippie beach bum to perform the ceremony.
This will be the third EnGraph wedding in as many years. Kyle and Allie got married in 2006 and David married Becca last May.
After working at EnGraph for almost half a decade, I am very used to capitalizing the 'G' on words that begin with "eng". Correctly typing "engaged" is going to require some training. I'm sure Kyle will attest to the same thing.
Official website, date and location will be coming shortly.
After we upgraded our server to Team Foundation Server 2008, our builds were failing. To be more specific, our builds were failing for lots of reasons, but the first problem was that the build server was unavailable.
We needed to stop the Team Build Service - the build service for TFS 2005 (and set the startup type to manual), before starting the Visual Studio Team Foundation Build service - the build service for TFS 2008.
Technorati tags:
TFS,
Team Build,
upgrade