Time categories with WPF and Exchange
Today and tomorrow I will present a short app I wrote for myself that others may find useful as a starting point.
Here at Microsoft, the use of Outlook and Exchange are of course ubiquitous (thanks WLW spell checker). So it’s no surprise that I have a vast amount of information stored in my folders for Calendar, Inbox, Task, etc. I’ve been thinking about how to improve my effectiveness, and one of the first steps is to understand where I am.
So what I did was whip up a small app that will look at my calendar items and their categories, and tell me where is it that I spent my time. Of course this requires categorizing your items, but it turns out that most of my calendar items already have some category because I create them from the tasks on the side (which I do categorize).
This is a C# WPF application, so we’ll take a look at the XAML today, and the code-behind tomorrow.
Let’s start from the end and work our way there.
So you can see there are three panels here.
- The top panel provides a place to put in your Exchange Server name.
- The second panel provides controls to select the start and end dates to categorize.
- The bottom panel provides a place to get the results, display them, and copy them to the clipboard.
Here is then the XAML for this page. This is a very “vanilla” page, without many customizations beyond font size and setting a background color. A few styles are used for some of the interesting elements like the panel labels and the panel borders, and grids are used to allow the controls to resize in ways that make sense.
<Window x:Class="TimeCategories.MainWindow"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
Title="Time Categories" Height="350" Width="525" Background="Gainsboro"
FontFamily="Calibri" FontSize="11pt"
>
<Window.Resources>
<Style x:Key="SectionBorderStyle" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="DarkGray" />
<Setter Property="BorderThickness" Value="2px" />
<Setter Property="Padding" Value="4px" />
<Setter Property="Margin" Value="4px" />
<Setter Property="CornerRadius" Value="4" />
</Style>
<Style x:Key="CaptionLabelStyle" TargetType="{x:Type Label}">
<Setter Property="FontWeight" Value="Bold" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Style="{StaticResource SectionBorderStyle}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Style="{StaticResource CaptionLabelStyle}"
Grid.ColumnSpan="3">
Settings
</Label>
<Label Grid.Row="1">Exchange Server:</Label>
<TextBox Name="ServerBox"
Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" />
</Grid>
</Border>
<Border Style="{StaticResource SectionBorderStyle}" Grid.Row="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Style="{StaticResource CaptionLabelStyle}"
Grid.ColumnSpan="2">
Date Selection
</Label>
<Label Grid.Row="1">Start Date:</Label>
<DatePicker Grid.Row="1" Grid.Column="1" Name="StartDateBox" />
<Label Grid.Row="2">End Date:</Label>
<DatePicker Grid.Row="2" Grid.Column="1" Name="EndDateBox" />
</Grid>
</Border>
<Border Style="{StaticResource SectionBorderStyle}" Grid.Row="2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Style="{StaticResource CaptionLabelStyle}">
Categories
</Label>
<Button Name="RefreshButton" Click="RefreshButtonClick"
Grid.Row="1">
Refresh
</Button>
<TreeView Grid.Row="2" Name="TimeCategoriesBox" />
<Button Name="CopyToClipboard" Click="CopyToClipboardClick"
Grid.Row="3">
Copy to Clipboard
</Button>
</Grid>
</Border>
</Grid>
</Window>
Enjoy!