Thursday, January 15, 2009

Outlook 2003 addin having issues?

If you're outlook 2003 addin is failing and outlook is only telling you that your plugin was disabled since it encountered an error, you can obtain the exception by starting outlook like this from the command line:

> set VSTO_SUPPRESSDISPLAYALERTS=0
> C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE


The familiar debugging box should then pop up telling you why your addin failed. If it doesn't pop up make sure that the value for the registry key at HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\Addins\YourAddInName\LoadBehavior = 3

Wednesday, January 14, 2009

Sorting a ListView in WPF

Sorting a ListView in WPF was really hard for me to figure out, but I found this solution in WPF Unleashed:


myListView.Items.SortDescriptions.Clear();
myListView.Items.SortDescriptions.Add(new SortDescription("AttributeName", ListSortDirection.Ascending));


This will keep the listview sorted even if it is bound to an ObservableCollection.

Tuesday, January 13, 2009

WPF Dynamic Auto Width

If you want to update your WPF interface dynamically and need to set an element's width to "Auto" as it's called in XAML, you can just set it's width to Double.NaN:


element.Width = Double.NaN;

Wednesday, December 24, 2008

WPF Hyperlink Open Browser

As my first post, I want to do something simple. Here was my problem: I wanted to have a hyperlink in WPF that would open in the browser when my link was clicked. In addition, I wanted the URL and title (display text) of the link to be obtained from a databinding. The following example assumes that the hyperlink has a parent that has a databinding where we can get the Url and LinkTitle fields from.

It can be achieved like this:
XAML:

<TextBlock>
<Hyperlink RequestNavigate="HandleLinkClick" NavigateUri="{Binding Path=Url}">
<TextBlock Text="{Binding Path=LinkTitle}"/>
</Hyperlink>
</TextBlock>

And the C#:

private void HandleLinkClick(object sender, RoutedEventArgs e) {
Hyperlink hl = (Hyperlink)sender;
string navigateUri = hl.NavigateUri.ToString();
Process.Start(new ProcessStartInfo(navigateUri));
e.Handled = true;
}