Archive for February, 2011

How to: Use UserControls in WPF XAML Windows

February 28, 2011

I created a UserControl called: “StatusBarControl” and it has a StatusBar contol with the following contols:  UserNameTextBlock, a  Lable for reporting progress, a ComboBox for displaying Styles of the form so the user can change them using the my.settings.UserStyle string,  and a StatusBar for showing progress. 

You first have to put in the header of the XAML Window the Following

In order to use a local UserControl you have to define the NameSpace of the Project that the Control resides in.


Code Snippet
  1. <Window x:Class="MyProjectWindow"
  2.     xmlns=";
  3.     xmlns:x=";
  4.     WindowStartupLocation="CenterOwner"
  5.     ResizeMode="NoResize"
  6.     Title="My Project" Height="480" Width="647"
  7.       xmlns:local="clr-namespace:MyProjectWPF_GUI"  
  8.     Name="MyProject">


Next you create the UserControl as a UserControl in your project.  My UserContol is called “StatusBarControl”.  Then you assign it its local name.

<local:StatusBarControl x:Name=”StatusBarControl…  />

Code Snippet
  1.         <StackPanel VerticalAlignment="Top" Orientation="Horizontal" HorizontalAlignment="Left" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Grid.RowSpan="2" Height="26" Margin="0,4,0,0" Name="StackPanel3" Width="526">
  2.             <Button Name="GetSmartIndexButton" Width="132" Height="23" ToolTip="You must get Smart Index Data before you can Submit to Mobius">Get Smart Index Data</Button>
  3.             <Button Name="ClearFieldsButton" Margin="3,0,0,0" Width="82" Height="23" ToolTip="Clears all Fields on this Tab.">Clear Fields</Button>
  4.             <Button Name="SubmitButton" Margin="3,0,0,0" Height="23" Width="116" ClickMode="Release" ToolTip="Submit the images to Mobius">Submit to Mobius</Button >
  5.         </StackPanel>
  7.         <!–<Rating Height="100" HorizontalAlignment="Right" Margin="0,0,-285.057,-48.343" Name="Rating1" VerticalAlignment="Bottom" Width="200" xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit" />–>
  8.         <local:StatusBarControl x:Name="StatusBarControl" HorizontalAlignment="Left" Grid.Row="3" Height="30" VerticalAlignment="Bottom" Grid.ColumnSpan="5" Width="655" Margin="-12,0,0,-5" />
  10.     </Grid>
  11. </Window>


It reference the UserControl File called “StatusBarControl.xaml” under a directory “UserControls” in the Project “MyProjectWPF_GUI”


Code Snippet
  1. <UserControl x:Class="StatusBarControl"
  2.              xmlns=";
  3.              xmlns:x=";
  4.              xmlns:mc=";
  5.              xmlns:d=";
  6.              mc:Ignorable="d"
  7.              d:DesignHeight="25" d:DesignWidth="650">
  8.     <Grid Height="31" Width="609">
  9.         <Grid Height="25" VerticalAlignment="Top">
  10.             <StatusBar Height="25" Name="statusBar1" VerticalAlignment="Top" Margin="-20,0,-41,0" />
  11.             <Label Content="Progress" FlowDirection="RightToLeft" Margin="0,0,41,0" Name="ProgressLabel" HorizontalAlignment="Right" Width="390" Visibility="Hidden" Height="25" VerticalAlignment="Top" />
  12.             <!–</StackPanel>–>
  13.         </Grid>
  14.         <StackPanel Orientation="Horizontal" Height="25" Name="StackPanel1" Margin="0,1,433,0" VerticalAlignment="Top">
  15.             <ComboBox DataContext="{Binding}" Height="23" ItemsSource="{Binding}" Name="StylesComboBox" Text="Hello" Visibility="Collapsed" Width="121" />
  16.             <Label Content="User: " Height="24" Name="UserNameTextBlock" Width="50" />
  17.         </StackPanel>
  18.     </Grid>
  19. </UserControl>


To update/refresj  the “StatusBarControl” you will need the Application.DoEvents that is in the System.Windows.Forms NameSpace…  System.Windows.Forms.Application.DoEvents()

Code Snippet
  1.     'In order to get the following code to update the color and the cursor you have to call the System.Windows.Forms.Application.DoEvents()
  2.         Me.Background = New SolidColorBrush(My.Settings.WaitFormColor)
  3.         Me.Cursor = Cursors.Wait
  4.         'Application.DoEvents()
  5.         System.Windows.Forms.Application.DoEvents()


That is it.  If you have any Questions, please leave me a comment.


How To: Use Windows.Resources and Resource.Dictionary for Setting Default Styles for ToolTip and Button Controls

February 28, 2011



In the XAML file you are working on add the following code if the Resource.Dictionary is named StylesDictionary.xaml and is located in a root directory called Styles.  The Project name is called MyProjectWPF_GUI.

Code Snippet
  2. <Window.Resources>
  3.     <ResourceDictionary>
  4.         <ResourceDictionary.MergedDictionaries>
  5.             <ResourceDictionary Source="pack://application:,,,/MYProjectWPF_GUI;component/Styles/StylesDictionary.xaml" />
  6.         </ResourceDictionary.MergedDictionaries>
  7.     </ResourceDictionary>
  8. </Window.Resources>



The Source  = pack://application:,,,/MyProjectWPF_GUI;component/Styles/StylesDictionary.xaml”

needs to have this “pack” syntax if you have a namespace declaration for “UserControls” like is used in this Window.


The error at runtime will be: “Set property ‘System.Windows.ResourceDictionary.Source’ threw an exception.”


Otherwise if you do not declare a namespace for a “UserControl” then you can call it by


Code Snippet
  1. <Window x:Class="MobiusWindow"
  2.     xmlns=";
  3.     xmlns:x=";
  4.     WindowStartupLocation="CenterOwner"
  5.     ResizeMode="NoResize"
  6.     Title="Submit to Mobius" Height="480" Width="647"
  7.       xmlns:local="clr-namespace:MYProjectWPF_GUI"  
  8.     Name="MobiusWin">



The Resource.Dictionary looks like the following.  Its filename is called StylesDictionary.xaml and is under a directory called Styles.

Code Snippet
  1. <ResourceDictionary xmlns=";
  2.     xmlns:x=""&gt;
  4.     <!– Default Button Style–>
  5.           <Style TargetType="Button">
  6.             <Setter Property="FontWeight" Value="Bold" />
  7.         </Style>
  9.     <!– Default ToolTip tyle–>
  10.         <Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
  11.             <Setter Property="OverridesDefaultStyle" Value="true"/>
  12.             <Setter Property="HasDropShadow" Value="True"/>
  13.             <Setter Property="Template">
  14.                 <Setter.Value>
  15.                     <ControlTemplate TargetType="ToolTip">
  16.                         <Border CornerRadius="7" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="5" BorderThickness="3,3,3,3">
  17.                             <Border.Background>
  18.                                 <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  19.                                     <GradientStop Color="#CF181818" Offset="0"/>
  20.                                     <GradientStop Color="#BE1C1C1C" Offset="1"/>
  21.                                 </LinearGradientBrush>
  22.                             </Border.Background>
  23.                             <Border.BorderBrush>
  24.                                 <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  25.                                     <GradientStop Color="#80FFFFFF" Offset="0"/>
  26.                                     <GradientStop Color="#7FFFFFFF" Offset="1"/>
  27.                                     <GradientStop Color="#FFFFF18D" Offset="0.344"/>
  28.                                     <GradientStop Color="#FFFFF4AB" Offset="0.647"/>
  29.                                 </LinearGradientBrush>
  30.                             </Border.BorderBrush>
  31.                             <StackPanel>
  32.                                 <TextBlock FontFamily="Tahoma" FontSize="11" Text="{TemplateBinding Content}" Foreground="#FFFFFFFF" />
  33.                             </StackPanel>
  34.                         </Border>
  35.                     </ControlTemplate>
  36.                 </Setter.Value>
  37.             </Setter>
  38.         </Style>
  39. </ResourceDictionary>


Good Luck

WPF ToolTips

February 25, 2011

Code Snippet
  1. <Button Content="Submit"> <Button.ToolTip> <ToolTip> <StackPanel> <TextBlock FontWeight="Bold">Submit Request</TextBlock> <TextBlock>Submits the request to the server.</TextBlock> </StackPanel> </ToolTip> </Button.ToolTip> </Button>

Creating a ToolTip for a Button

Code Snippet
  1. <Button Content="Submit"> <Button.ToolTip> <ToolTip> <StackPanel> <TextBlock FontWeight="Bold">Submit Request</TextBlock> <TextBlock>Submits the request to the server.</TextBlock> </StackPanel> </ToolTip> </Button.ToolTip> </Button>

Code Snippet
  1. <Button IsEnabled="False" ToolTip="Saves the current document" ToolTipService.ShowOnDisabled="True" Content="Save"> </Button>

How to show ToolTips on Disabled Controls

Code Snippet
  1. <Button IsEnabled="False" ToolTip="Saves the current document" ToolTipService.ShowOnDisabled="True" Content="Save"> </Button>


How to Change the Show Duration of a ToolTip

Code Snippet
  1. <Button ToolTip="Saves the current document" ToolTipService.ShowDuration="20" Content="Save"> </Button>

How to Setup Logging using Enterprise Library in .NET

February 25, 2011


Here is the lines of code you put into the app.config file for the Services and GUI to get logging working using Enterprise Library.  This code is using the Enterprise Library 4.0

I used this in NADP, FBSubmit, and FBEdTrack



Code Snippet
  1.  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
  2. defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
  3.      <listeners>
  4.          <add fileName="c:\logs\FBSubmit\trace.log" header="—————————————-"
  5.   footer="—————————————-" formatter=""
  6.   listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  7.   traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  8.   name="FlatFile TraceListener" />
  9.          <add fileName="c:\logs\FBSubmit\trace.log" footer="—————————————-"
  10.   formatter="" header="—————————————-"
  11.   rollFileExistsBehavior="Overwrite" rollInterval="None" rollSizeKB="0"
  12.   timeStampPattern="yyyy-MM-dd" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  13.   traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  14.   name="Rolling Flat File Trace Listener" />
  15.      </listeners>
  16.      <formatters>
  17.          <add template="Timestamp: {timestamp} Message: {message} Category: {category} Priority: {priority} EventId: {eventid} Severity: {severity} Title:{title} Machine: {machine} Extended Properties: {dictionary({key} – {value} )}"
  18.   type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  19.   name="Text Formatter" />
  20.      </formatters>
  21.      <categorySources>
  22.          <add switchValue="All" name="General" />
  23.      </categorySources>
  24.      <specialSources>
  25.          <allEvents switchValue="All" name="All Events">
  26.              <listeners>
  27.                  <add name="FlatFile TraceListener" />
  28.                  <add name="Rolling Flat File Trace Listener" />
  29.              </listeners>
  30.          </allEvents>
  31.          <notProcessed switchValue="All" name="Unprocessed Category" />
  32.          <errors switchValue="All" name="Logging Errors &amp; Warnings" />
  33.      </specialSources>
  34.  </loggingConfiguration>

Microsoft Windows Phone 7 Status

February 13, 2011


I was reading some articles this weekend regarding the new TouchPad by Hewlett-Packard due out this summer, and I got some statistics regarding how many apps Apple and Android have.

Here is the breakdown…

Apple has over 300,000 apps that can be played on the iPhone or iPad.

Android has over 100,000 apps that are for the Android phone.

Hewlett-Packard is trying to get developers for their WebOS platform which runs on their phones and soon to be released TouchPad.

But, the most interesting news is that Microsoft has over 150,000 registered developers for the Windows Phone 7 (WP7).  Which means that If each of the developers wrote one program, they would surpass the Hewlett-Packard and Android market for available apps.  

Get ready everyone, the Windows Phone 7 wave of apps are coming!


New Features of Internet Explorer 9 (IE9)

February 11, 2011

Below is a breakdown of a video that Microsoft released on the web…

There has been a release candidate (RC) of IE9 this week.  We thought you might want to know some of them.

1. Pin Sites with multiple web pages.  Now you can have a pin site for Social Media, one for Finance, one for Hobbies, etc…

2. Tab placement.  With 2 clicks you can put your tabs on its own line in the browser, reducing clutter.

3. Close tab by clicking on the X(close).  You do not have to navigate to the page by picking the tab first.

4.  Highlight some words in your browser and copy them then by pressing ctrl-shift-L to have the browser search for that text.

5.  More browser space and less header space.  This allows the browser to be thought more as an application.  Less is best.


Over 25 million downloads have been for IE9(RC). 

It works on Windows 7.

It core is HTML 5.

Very fast graphics.


To get the latest version of Internet Explorer 9, visit:


Enjoy… SKJ