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

February 28, 2011

 

<Window.Resources/>

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
  1.  
  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>

 

Note:

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.

xmlns:local="clr-namespace:MyProjectWPF_GUI" 

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

Source=”/Styles/StylesDictionary.xaml”

Code Snippet
  1. <Window x:Class="MobiusWindow"
  2.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
  3.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot;
  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">

 

<Resource.Dictionary/>

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="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
  2.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  3.  
  4.     <!– Default Button Style–>
  5.           <Style TargetType="Button">
  6.             <Setter Property="FontWeight" Value="Bold" />
  7.         </Style>
  8.     
  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

Advertisements

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=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  7.   traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, 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=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  13.   traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, 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=4.0.0.0, 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

Introduction

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!

image

New Features of Internet Explorer 9 (IE9)

February 11, 2011

Below is a breakdown of a video that Microsoft released on the web… http://channel9.msdn.com/posts/First-look-at-5-features-of-IE9-RC

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: http://ie.microsoft.com/testdrive/

 

Enjoy… SKJ

Windows Live Writer for Windows XP Installation

January 6, 2011

 

Go to the Windows Live Writer for Windows XP Web Site and select the Language of English and then press the Download now Button.

image

You get the following dialog box.  Select the Run Button.

image

Windows Live Writer 2011 Installation

January 6, 2011

Go to the Windows Live Writer 2011 Web Site and select the Download now Button.  image

 

You get the following dialog box.  Select the Run Button.

image

Video Training Sites (Steven K James’s recommendations)

December 22, 2010

Here are the sites that I use for Training and Certification.  Some are Free and some cost a Subscription price.  Please contact me if you are interested in the subscription site purchases.  I am a reseller of them.

 

FREE Training Sites

Dr Dobb’s TV

 

Channel 9 Videos about the people building Microsoft Products & Services

 

Subscription Training Sites (Contact me for pricing.  I am a vendor and user of these sites.)

.NET Tutorial Videos from Beginner to Expert  LearnVisualStudio.NET

 

Microsoft Training at AppDev IT Training, Developer Training, Microsoft Certification Training,

 

Contact Information:  Steven.James@1800thenerd.com

Or call: 1-800-The-Nerd

ASP.NET Interview with Scott Guthrie

December 22, 2010

Scott Guthrie: The Man Who Created ASP.NET


A Bytes by MSDN interview with ASP.NET creator Scott Guthrie who talks about what’s new in Silverlight 4. Click on video to learn about it on Dr. Dobb’s Microsoft Resource Center.

Picture Resizer 5.0 Application used in an “Right Click/Send” To Application

December 22, 2010

 

Batch Picture Resize

 

Advanced PhotoResize.exe settings

This is the area where I used the command line arguments to resize to a specific size of image. 

 

Example of C# code is:

s is the image location and name: 

Code Snippet
  1. OpenPhotoResize(@"-o " + "-cC:\\ResizedImages\\<PATH><NAME>.jpg " + s);

OpenPhotoResize method is:

f is the parameter that is passed to the PhotoResizer400

Code Snippet
  1. static void OpenPhotoResize(string f)
  2. {
  3.     ProcessStartInfo startInfo = new ProcessStartInfo();
  4.     startInfo.FileName = "C:\\PhotoResize400.exe";
  5.     startInfo.Arguments = f;
  6.     Process.Start(startInfo);
  7. }