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

Rock chalk!
A lot of times, I need to show or hide a textbox based the value of a checkbox.


In WinForms 2.0. This was easy:
myTextBox.Visible = myCheckBox.Checked;
With the new Visibility Enum in WPF, this becomes a bit trickier. To accomplish this, you need to implement a converter that will accept a boolean value and return a visibility value. The converter I used is here:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Data;
using System.Windows;
namespace ParaPlan.Converters
{
public class BooleanToHiddenVisibility : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Visibility rv = Visibility.Visible;
try
{
var x = bool.Parse(value.ToString());
if (x)
{
rv = Visibility.Visible;
}
else
{
rv = Visibility.Collapsed;
}
}
catch (Exception)
{
}
return rv;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
}
}
The XAML code to use this is below. The important parts are:
xmlns:converters="clr-namespace:ParaPara.Converters"
converters:BooleanToHiddenVisibility x:Key="boolToVis"
TextBox ... Visibility={Binding Path=IsChecked, ElementName=checkViewTextBox...}"
<Window x:Class="ParaPlan.Windows.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:converters="clr-namespace:ParaPlan.Converters">
<StackPanel Orientation="Vertical">
<StackPanel.Resources>
<converters:BooleanToHiddenVisibility x:Key="boolToVis"/>
</StackPanel.Resources>
<CheckBox Content="Check to show text box below me" Name="checkViewTextBox"/>
<TextBox Text="only seen when above checkbox is checked"
Visibility="{Binding Path=IsChecked, ElementName=checkViewTextBox, Converter={StaticResource boolToVis}}"/>
</StackPanel>
</Window>
Now we can cleanly show or hide an element based on a checkbox using just XAML code.
Technorati tags:
WPF,
XAML,
converter

Lawrence is gearing up for the biggest Kansas-Missouri game since ever. A bunch of business have changed their billboards to give the undefeated Jayhawks well deserved props. I took some pictures of the billboards and put them on a Google Map mashup.
Rock chalk! Hope the MU fans are looking forward to a bowl game not in January.