<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Paul Sheriff's Blog for the Real World</title><link>http://weblogs.asp.net/psheriff/default.aspx</link><description>This blog is for my ramblings and to share my tips, tricks and advice garnered over 20+ years in the IT industry. I like to focus on topics that affect real-world business application developers.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/PaulSheriffsOuterCircleBlog" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>Creating a Base Window Class in WPF</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/YmnrgqmkKYk/creating-a-base-window-class-in-wpf.aspx</link><pubDate>Mon, 02 Nov 2009 20:42:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7245461</guid><dc:creator>psheriff</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7245461</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/11/02/creating-a-base-window-class-in-wpf.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Unlike Windows Forms, there is no Visual Inheritance in WPF. Luckily you don’t need visual inheritance as you can use User Controls to get a re-usable UI. There are times, however, when you want a base Window class so you can have common functionality in all your WPF windows. To accomplish this you can create a base class from which all your WPF windows can inherit. To use the base class you will need to make one simple change in both the XAML and in your code-behind class.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;&amp;lt;Window&amp;gt; Element and Window Class&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;When you add a new Window to a WPF application it builds a .XAML file and a code-behind file. The XAML file has a &amp;lt;Window&amp;gt; element and the code-behind file has a partial class that inherits from “Window” or “System.Windows.Window” to be more specific. Notice the x:Class=”&amp;lt;Namespace&amp;gt;.&amp;lt;ClassName&amp;gt;” syntax in the XAML (See Figure 1). This x:Class name attribute must have the same name as the partial class in the code-behind. At compile time, the .XAML file is converted into a partial class that has the same name as the name of the class in the code-behind and inherits from the name of the top level element in the XAML; in this case “Window”.&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 586px; HEIGHT: 301px" src="http://www.pdsa.com/images/WindowInheritance.jpg" width=586 height=301 mce_src="http://www.pdsa.com/images/WindowInheritance.jpg"&gt;&lt;BR&gt;Figure 1: The Window class and the inherited Window must match.&lt;/P&gt;
&lt;P mce_keep="true"&gt;As long as these two items match the two elements in the partial class in the code-behind the compiler will be happy. If either of these two elements does not match, you will receive a compiler error.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Inherit from the Window Class&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now that you understand the basics of how the XAML and the code-behind are put together, you can now create a base Window class and modify the XAML and code-behind to use this new class.&lt;/P&gt;
&lt;P mce_keep="true"&gt;If you wish to follow along with this article, create a new WPF application in Visual Studio. Add a new class to your project named &lt;STRONG&gt;WindowBase&lt;/STRONG&gt;. Modify this newly added class to inherit from the Window class. Add the following Imports/using statements at the top of the WindowBase class.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;using System.Windows;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Imports System.Windows&lt;/P&gt;
&lt;P mce_keep="true"&gt;The WindowBase class needs to inherit from the Window class by changing the code to look like the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;using System;&lt;BR&gt;using System.Windows;&lt;/P&gt;
&lt;P mce_keep="true"&gt;namespace WpfApplication1&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; public class WindowBase : Window&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;Visual Basic&lt;BR&gt;Imports System.Windows&lt;/P&gt;
&lt;P mce_keep="true"&gt;Public Class WindowBase&lt;BR&gt;&amp;nbsp; Inherits Window&lt;BR&gt;End Class&lt;/P&gt;
&lt;P mce_keep="true"&gt;Modify the code-behind of the Window1.xaml file to inherit from the WindowBase class you just created. Your Window1 code-behind should now look like the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;public partial class Window1 : &lt;STRONG&gt;WindowBase&lt;/STRONG&gt;&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; public Window1()&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Class Window1 &lt;BR&gt;&amp;nbsp; &lt;STRONG&gt;Inherits WindowBase&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;End Class&lt;/P&gt;
&lt;P mce_keep="true"&gt;If you were to compile the WPF application right now, you will receive the error message “Base class 'System.Windows.Window' specified for class 'Window1' cannot be different from the base class 'WindowBase' of one of its other partial types.” The reason is because while you changed the code behind to inherit from the WindowBase class, you need to change the XAML markup to reflect this same change.&lt;/P&gt;
&lt;P mce_keep="true"&gt;The change you need to make is you need to modify the &amp;lt;Window&amp;gt; element to be &amp;lt;WindowBase&amp;gt;. However, &amp;lt;WindowBase&amp;gt; is not a part of any of the imported xml namespaces that are a normal part of the XAML markup. Thus, you need to add a namespace reference to the assembly that contains the WindowBase class. If you created a default WPF application project, the namespace you will add to the XAML is the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;xmlns:src="clr-namespace:WpfApplication1"&lt;/P&gt;
&lt;P mce_keep="true"&gt;Once you have added this namespace with the prefix of “src” you can now change the &amp;lt;Window&amp;gt; element to &amp;lt;src:WindowBase&amp;gt;. Be sure you modify the closing &amp;lt;/Window&amp;gt; element to &amp;lt;/src:WindowBase&amp;gt;. The complete source code for the XAML is shown below.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;&amp;lt;&lt;STRONG&gt;src:WindowBase&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp; x:Class="WpfApplication1.Window1"&lt;BR&gt;&amp;nbsp; xmlns="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/A&gt;"&lt;BR&gt;&amp;nbsp; xmlns:x="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/A&gt;"&lt;BR&gt;&amp;nbsp; &lt;STRONG&gt;xmlns:src="clr-namespace:WpfApplication1"&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp; Title="Window1" Height="300" Width="300"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid&amp;gt;&amp;lt;/Grid&amp;gt;&lt;BR&gt;&amp;lt;/&lt;STRONG&gt;src:WindowBase&lt;/STRONG&gt;&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;&amp;lt;&lt;STRONG&gt;src:WindowBase &lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp; x:Class="Window1"&lt;BR&gt;&amp;nbsp; xmlns="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/A&gt;"&lt;BR&gt;&amp;nbsp; xmlns:x="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/A&gt;"&lt;BR&gt;&amp;nbsp; &lt;STRONG&gt;xmlns:src="clr-namespace:WpfApplication1"&lt;/STRONG&gt;&lt;BR&gt;&amp;nbsp; Title="Window1" Height="300" Width="300"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid&amp;gt;&amp;lt;/Grid&amp;gt;&lt;BR&gt;&amp;lt;/&lt;STRONG&gt;src:WindowBase&lt;/STRONG&gt;&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;At this point you should be able to compile the application and everything should compile correctly.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Adding Functionality&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now that you have a base Window class you can add code to that class that can be used in all of your WPF Windows. Once piece of functionality you might need is to check if your Window is in design mode or runtime. Add the following property to your WindowBase class.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;public bool IsInDesignMode&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; get&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return System.ComponentModel.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DesignerProperties.GetIsInDesignMode(this);&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Public ReadOnly Property IsInDesignMode() As Boolean&lt;BR&gt;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return System.ComponentModel. _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DesignerProperties.GetIsInDesignMode(Me)&lt;BR&gt;&amp;nbsp; End Get&lt;BR&gt;End Property&lt;/P&gt;
&lt;P mce_keep="true"&gt;From within your Window that inherits from the WindowBase class you can test to see if you are in design mode or in runtime mode.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;if(IsInDesignMode)&lt;BR&gt;&amp;nbsp; // Do Something&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;If IsInDesignMode Then&lt;BR&gt;&amp;nbsp; ' Do Something&lt;BR&gt;End If&lt;/P&gt;
&lt;P mce_keep="true"&gt;Another piece of code that might come in handy in your WPF windows is the ability to read a resource dictionary XAML file and load it into the Resources of the Window. Below is the code you would add to the WindowBase class to do this.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;using System.IO;&lt;BR&gt;using System.Windows.Markup;&lt;/P&gt;
&lt;P mce_keep="true"&gt;public void OpenResourceDictionary(string fileName)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; ResourceDictionary dic = null;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; if (File.Exists(fileName))&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (FileStream fs = new FileStream(fileName, FileMode.Open))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dic = (ResourceDictionary)XamlReader.Load(fs);&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Resources.MergedDictionaries.Add(dic);&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new FileNotFoundException(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Can't open resource file: " + fileName + &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " in the method OpenResourceDictionary().");&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Imports System.IO&lt;BR&gt;Imports System.Windows.Markup&lt;/P&gt;
&lt;P mce_keep="true"&gt;Public Sub OpenResourceDictionary(ByVal fileName As String)&lt;BR&gt;&amp;nbsp; Dim dic As ResourceDictionary = Nothing&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; If File.Exists(fileName) Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Using fs As New FileStream(fileName, FileMode.Open)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dic = DirectCast(XamlReader.Load(fs), ResourceDictionary)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Using&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.Resources.MergedDictionaries.Add(dic)&lt;BR&gt;&amp;nbsp; Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Throw New FileNotFoundException( _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "Can't open resource file: " &amp;amp; fileName &amp;amp; _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; " in the method OpenResourceDictionary().")&lt;BR&gt;&amp;nbsp; End If&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;When you wish to load a new resource dictionary file at runtime into your Window you may do so with some very simple code from within your Window.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;OpenResourceDictionary("D:\Samples\Green.xaml");&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;OpenResourceDictionary("D:\Samples\Green.xaml")&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;So, that is all there is to creating your own base Window class from which all your Window objects can inherit. There is a lot of functionality that you will want to make available to your Window classes. Creating a base Window class is a great way to expose this functionality. It just takes a little bit of tweaking to your XAML and your code-behind to get all this great functionality.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;NOTE: You can download the complete sample code&amp;nbsp;at my website. &lt;A href="http://www.pdsa.com/downloads"&gt;&lt;FONT color=#006ff7&gt;http://www.pdsa.com/downloads&lt;/FONT&gt;&lt;/A&gt;. Choose Tips &amp;amp; Tricks, then "WPF Window Inheritance" from the drop-down.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7245461" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/WPF/default.aspx">WPF</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/11/02/creating-a-base-window-class-in-wpf.aspx</feedburner:origLink></item><item><title>Create a Login Screen in Silverlight 3</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/7X508qD0BsI/create-a-login-screen-in-silverlight.aspx</link><pubDate>Thu, 29 Oct 2009 19:30:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7242724</guid><dc:creator>psheriff</dc:creator><slash:comments>7</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7242724</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/10/29/create-a-login-screen-in-silverlight.aspx#comments</comments><description>&lt;P&gt;After my last blog post on “Create a Login Window in WPF”, I had a lot of requests for how to create the same login screen in Silverlight 3. There are actually just a few changes that had to be made to get the same look in feel in Silverlight 3. Figure 1 shows what this login screen looks like under Silverlight.&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG title="Silverlight 3 Login Screen" alt="Silverlight 3 Login Screen" src="http://www.pdsa.com/images/sllogin.jpg" mce_src="http://www.pdsa.com/images/sllogin.jpg"&gt;&lt;BR&gt;Figure 1: A Login Screen in Silverlight 3 (SLLogin.jpg)&lt;/P&gt;
&lt;P&gt;Let’s take a look at how to create this screen in Silverlight.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Create a Silverlight Application&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The first step is to create a Silverlight Application using VS.NET 2008. Once you have this created, open the MainPage.xaml that is created by the template. For this particular User Control you will set a specific width and height on the Grid control.&lt;/P&gt;
&lt;P&gt;&amp;lt;Grid x:Name="LayoutRoot" Width="500" Height="200"&amp;gt;&lt;BR&gt;&amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P&gt;Next you will create some resources to help style the various elements you will be using on this Silverlight page. I have set some specific height properties on the controls for this page. I did this so the controls would not look stretched out. There might be a better way to do this, but I am still just learning Silverlight!&lt;/P&gt;
&lt;P&gt;&amp;lt;Grid.Resources&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Style x:Key="tbStyle"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TargetType="TextBlock"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Margin"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="4"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Style x:Key="textBoxStyle"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TargetType="TextBox"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Margin"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="4"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="MinWidth"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="200"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="HorizontalAlignment"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="Left"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Style x:Key="passStyle"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TargetType="PasswordBox"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Margin"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="4"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="MinWidth"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="200"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="HorizontalAlignment"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="Left"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Style x:Key="buttonStyle"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TargetType="Button"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Margin"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="6"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Padding"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="4"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="MinWidth"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Value="50"&amp;gt;&amp;lt;/Setter&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;BR&gt;&amp;lt;/Grid.Resources&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Border&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Now that you have created the Grid size and the resources to be used within the Grid you now create the look for the outside border of the window. A Border control is used to form the outside of this login screen. You will set the CornerRadius attribute to “10” to give the nice rounded corners. You can set the BorderBrush to “Gray” and the BorderThickness to “3”. To achieve the shadow effect on this window, you will use the Border.Effect and the DropShadowEffect. Below is the xaml for the Border control.&lt;/P&gt;
&lt;P&gt;&amp;lt;Border CornerRadius="10"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BorderBrush="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BorderThickness="3"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Background="Beige"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Padding="4"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Border.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="16" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Border.Effect&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ...&lt;BR&gt;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;lt;/Border&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Using a Grid Layout&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;To place each of the login screen elements within the border, a Grid control is used with specific column and row definitions. There are three columns in this login screen. The first column is for the image of the key, the second is for the labels and the third is for the TextBox, PasswordBox and Button controls.&lt;/P&gt;
&lt;P&gt;&amp;lt;Grid&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid.ColumnDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition Width="60" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition Width="100" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition Width="*" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Grid.ColumnDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid.RowDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition Height="*" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition Height="Auto" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition Height="Auto" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition Height="Auto" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Grid.RowDefinitions&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; ...&lt;BR&gt;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P&gt;&amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Placing the Key Image&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The Key image that is in the upper left hand corner of this login screen is placed there by using a StackPanel control and an Image control. The StackPanel gives us just a little more control over the placement within the Grid. Notice the Grid.Column, Grid.Row and Grid.RowSpan attributes that are set on the StackPanel. The Grid.Row and Grid.Column specify in which row and column of the grid you wish to display the StackPanel. The Grid.RowSpan allows the key to float down over the next three rows of the Grid control. If you were to use a smaller or larger key image, then you would probably need to adjust this attribute accordingly. The Image control sets the source of its image to the Key.jpg file located in the Images folder. A drop shadow effect is applied to this image control just like you did with the Border control.&lt;/P&gt;
&lt;P&gt;&amp;lt;StackPanel Grid.Column="0"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="0"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.RowSpan="3"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Image Name="imgKey"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="8"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Source="Images/Key.jpg"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Image.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="8" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Image.Effect&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Image&amp;gt;&lt;BR&gt;&amp;lt;/StackPanel&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Large Title Label&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The large label across the top of the login screen is simply a Label control with the appropriate Grid.Row, Grid.Column and Grid.ColumnSpan attributes set for placement. A FontSize of 18 is applied to make the text appear larger than the other labels on this screen. A Margin of 10 is used to give us some spacing from the border of the grid.&lt;/P&gt;
&lt;P&gt;&amp;lt;Label Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="0"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.ColumnSpan="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FontSize="18"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="10"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text="Please Login To Access This Application" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Login Data Controls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The controls that gather the user name and password should be fairly familiar to you if you have been doing any Silverlight development. Each control is placed into a specific row and column of the Grid control. Instead of a Label control like you use in WPF, a TextBlock control is used in Silverlight.&lt;/P&gt;
&lt;P&gt;&amp;lt;TextBlock Style="{StaticResource tbStyle}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="0"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.ColumnSpan="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FontSize="18"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="10"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text="Please Login To Access This Application" /&amp;gt;&lt;BR&gt;&amp;lt;TextBlock Style="{StaticResource tbStyle}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text="User Name" /&amp;gt;&lt;BR&gt;&amp;lt;TextBox Style="{StaticResource textBoxStyle}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Column="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="txtUserName" /&amp;gt;&lt;BR&gt;&amp;lt;TextBlock Style="{StaticResource tbStyle}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="2"&amp;gt;Password&amp;lt;/TextBlock&amp;gt;&lt;BR&gt;&amp;lt;PasswordBox Style="{StaticResource passStyle}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Column="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="txtPassword" /&amp;gt;&lt;/P&gt;
&lt;P&gt;Notice the use of the Style attribute to apply the styles defined in the Grid.Resources section. In WPF you can apply global styles to a target control. In Silverlight you have to assign the style individually to each control.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Buttons&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The two buttons at the bottom of the screen are placed into the last row of the Grid control and into the second column of the grid by wrapping them into a StackPanel. The StackPanel has its HorizontalAlignment attribute set to Center and it’s Orientation attribute to Horizontal to allow the buttons to be centered within the StackPanel and to have the buttons appear side-by-side to each other.&lt;/P&gt;
&lt;P&gt;&amp;lt;StackPanel Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="3"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="10"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HorizontalAlignment="Center"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Orientation="Horizontal"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Button Style="{StaticResource buttonStyle}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="btnCancel"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Content="Cancel"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="8" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Button Style="{StaticResource buttonStyle}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="btnLogin"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Content="Login"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="8" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;lt;/StackPanel&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;That is all there is to creating a nice looking login screen in Silverlight 3. Using the DropShadowEffect can add some spice to an otherwise flat-looking screen. I did not show any code for the login process as that will be dependent on your particular application. However, I hope this article gave you some ideas on how to layout screens in Silverlight 3.&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;NOTE: You can download the complete sample code&amp;nbsp;at my website. &lt;A href="http://www.pdsa.com/downloads"&gt;&lt;FONT color=#006ff7&gt;http://www.pdsa.com/downloads&lt;/FONT&gt;&lt;/A&gt;. Choose Tips &amp;amp; Tricks, then "Silverlight 3 Login Screen" from the drop-down.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;&lt;FONT color=#006ff7&gt;http://www.pdsa.com/Event/Blog&lt;/FONT&gt;&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7242724" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/Silverlight+3/default.aspx">Silverlight 3</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/10/29/create-a-login-screen-in-silverlight.aspx</feedburner:origLink></item><item><title>Create a Login Window in WPF</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/KuN9EN3aq3I/create-a-login-window-in-wpf.aspx</link><pubDate>Wed, 28 Oct 2009 03:52:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7241117</guid><dc:creator>psheriff</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7241117</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/10/27/create-a-login-window-in-wpf.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Most business applications require some sort of security system. You can always use Windows Authentication to authenticate a user, but sometimes you might want your own authentication scheme. When you do, you will need to create a login screen for your user to enter her login id and password. This article will explore creating a login window in WPF.&lt;/P&gt;
&lt;P mce_keep="true"&gt;The UI for your login screen can contain any images and controls that you would like. In Figure 1 you can see a sample login screen that has an image of a key, a large title label across the top, two labels, a text box, a password box and two button controls. You can also make the border of the window rounded so that there is no close, minimize or maximize button and no title bar.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 554px; HEIGHT: 354px" title="WPF Login Form" alt="WPF Login Form" src="http://www.pdsa.com/images/WPFLogin.jpg" width=554 height=354 mce_src="http://www.pdsa.com/images/WPFLogin.jpg"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Figure 1: A Login Screen &lt;/P&gt;
&lt;P mce_keep="true"&gt;Of course this is just one version of a login screen but let’s take a look at how this is put together.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Creating the Window&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;To start, you need to create a window with no border and can be made into any shape you want. To do this you will set a few different attributes. The WindowStyle attribute normally allows you to set a single border, three-D border, or a Tool Window border. Setting this attribute to None will eliminate the border. The ShowInTaskbar attribute is optional, but if you are building a login screen you probably won’t want this window to show up in the Task Bar as it is going to be modal style form. The next two attributes, AllowsTransparency and Background work together. You must set AllowsTransparency to True to allow the Background to be set to Transparent. If you do not set these two attributes, then your border will still show up. Below is the xaml for this window.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;Window ...&lt;BR&gt;&amp;nbsp;&amp;nbsp; WindowStartupLocation="CenterScreen"&lt;BR&gt;&amp;nbsp;&amp;nbsp; AllowsTransparency="True"&lt;BR&gt;&amp;nbsp;&amp;nbsp; ShowInTaskBar=False&lt;BR&gt;&amp;nbsp;&amp;nbsp; Background="Transparent"&lt;BR&gt;&amp;nbsp;&amp;nbsp; WindowStyle="None"&lt;BR&gt;&amp;nbsp;&amp;nbsp; SizeToContent="WidthAndHeight"&lt;BR&gt;&amp;nbsp;&amp;nbsp; FocusManager.FocusedElement=&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "{Binding ElementName=txtUserName}"&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp; ...&lt;BR&gt;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;/Window&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;There are three additional attributes that are set on this window. The WindowStartupLocation attribute is set to “CenterScreen”&amp;nbsp; to ensure that the login screen is displayed in the middle of the screen when it is shown. You also set the SizeToContent attribute to WidthAndHeight to just take as much room for this window as the controls need that are contained within this window. The FocusManager.FocusedElement attribute is data-bound to the textbox control next to the User Name label. This tells WPF to place the cursor in this textbox once the screen is displayed.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;The Border&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now that you have the Window xaml defined you now can create the look for the outside border of the window. A Border control is used to form the outside of this login screen. You will set the CornerRadius attribute to “10” to give the nice rounded corners. You can set the BorderBrush to “Gray” and the BorderThickness to “3”. You also want to give this border a nice wide Margin to allow room for the DropShadowEffect that we add to the outside of this border. If you do not do this, then the drop shadow will be chopped off. To achieve the shadow effect on this window, you will use the new Border.Effect and the DropShadowEffect that was added in WPF 3.5. This drop shadow effect is drawn using the Graphical Processing Unit (GPU) instead of being drawn using software. Thus drawing drop shadows is much more performant than in previous versions of WPF.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;Border CornerRadius="10"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BorderBrush="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BorderThickness="3"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Background="Beige"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="24"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Padding="4"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Border.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="16" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Border.Effect&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp; ...&lt;BR&gt;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;/Border&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Using a Grid Layout&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;To place each of the login screen elements within the border, a Grid control is used with specific column and row definitions. There are three columns in this login screen. One for the image of the key, one for the labels and one for the TextBox, PasswordBox and Button controls.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;Grid&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid.ColumnDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition Width="60" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition Width="100" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition Width="*" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Grid.ColumnDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid.RowDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Grid.RowDefinitions&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp; ...&lt;BR&gt;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Placing the Key Image&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The Key image that is in the upper left hand corner of this login screen is placed there by using a StackPanel control and an Image control. The StackPanel gives us just a little more control over the placement within the Grid. Notice the Grid.Column, Grid.Row and Grid.RowSpan attributes that are set on the StackPanel. The Grid.Row and Grid.Column specify in which row and column of the grid you wish to display the StackPanel. The Grid.RowSpan allows the key to float down over the next three rows of the Grid control. If you were to use a smaller or larger key image, then you would probably need to adjust this attribute accordingly. The Image control sets the source of its image to the Key.jpg file located in the /Images folder. A drop shadow effect is applied to this image control just like you did with the Border control.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;StackPanel Grid.Column="0"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="0"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.RowSpan="3"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Image Name="imgKey"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="8"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Source="/Images/Key.jpg"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Image.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="8" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Image.Effect&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Image&amp;gt;&lt;BR&gt;&amp;lt;/StackPanel&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;The Large Title Label&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The large label across the top of the login screen is simply a Label control with the appropriate Grid.Row, Grid.Column and Grid.ColumnSpan attributes set for placement. A FontSize of 18 is applied to make the text appear larger than the other labels on this screen. A Margin of 10 is used to give us some spacing from the border of the grid.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;Label Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="0"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.ColumnSpan="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FontSize="18"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="10"&amp;gt;Please Login To Access This Application&lt;BR&gt;&amp;lt;/Label&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;The Login Data Controls&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The controls that gather the user name and password should be fairly familiar to you if you have been doing any WPF at all. Each control is placed into a specific row and column of the Grid control. Notice the use of the Tooltip attribute on the TextBox and the PasswordBox control. This gives the user an idea of what to put into each control if they hover their mouse over that control.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;Label Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="1"&amp;gt;User Name&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;lt;TextBox Grid.Column="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ToolTip="Enter Your User Name"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="txtUserName" /&amp;gt;&lt;BR&gt;&amp;lt;Label Grid.Column="1"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="2"&amp;gt;Password&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;lt;PasswordBox Grid.Column="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ToolTip="Enter Your Password"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="txtPassword" /&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;The Buttons&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The two buttons at the bottom of the screen are placed into the last row of the Grid control and into the second column of the grid by wrapping them into a StackPanel. The StackPanel has its HorizontalAlignment attribute set to Center and it’s Orientation attribute to Horizontal to allow the buttons to be centered within the StackPanel and to have the buttons appear side-by-side to each other.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;StackPanel Grid.Column="2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Grid.Row="3"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="10"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HorizontalAlignment="Center"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Orientation="Horizontal"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Button Name="btnCancel"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IsCancel="True"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Content="Cancel"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Click="btnCancel_Click"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="8" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Button Name="btnLogin"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IsDefault="True"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Content="Login"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Click="btnLogin_Click"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DropShadowEffect Color="Gray"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Opacity=".50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ShadowDepth="8" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Button.Effect&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;lt;/StackPanel&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;There are two special attributes that are set on these buttons. The IsCancel attribute is set to true on the Cancel button. Setting this attribute to true will fire the click event procedure on the Cancel button if the user presses the Escape key. The IsDefault attribute is set to true on the on the Login button. Setting this attribute to true will fire the click event procedure on the Login button if the user presses the Enter key.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Writing the Code for the Login Screen&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;In each of the click event procedures you will need to close the screen. In the Cancel click event procedure you will set the DialogResult property of the screen to a false value. This will inform the calling procedure that the user clicked on the Cancel button on this screen. In the Login click event procedure you will set the DialogResult property of the screen to a true value. This informs the calling procedure that the user clicked on the Login button and was authenticated. I am leaving it up to you to write the code for authenticating the user. Here is the code for the Cancel event procedure.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;C#&lt;BR&gt;&lt;/STRONG&gt;private void btnCancel_Click(object sender, RoutedEventArgs e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; DialogResult = false;&lt;BR&gt;&amp;nbsp; this.Close();&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Visual Basic&lt;BR&gt;&lt;/STRONG&gt;Private Sub btnCancel_Click(ByVal sender As System.Object, _&lt;BR&gt;&amp;nbsp;ByVal e As System.Windows.RoutedEventArgs)&lt;BR&gt;&amp;nbsp; DialogResult = False&lt;BR&gt;&amp;nbsp; Me.Close()&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;And, here is the code for the Login event procedure.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;C#&lt;BR&gt;&lt;/STRONG&gt;private void btnLogin_Click(object sender, RoutedEventArgs e)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; // Write code here to authenticate user&lt;BR&gt;&amp;nbsp; // If authenticated, then set DialogResult=true&lt;BR&gt;&amp;nbsp; DialogResult = true;&lt;BR&gt;&amp;nbsp; this.Close();&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Visual Basic&lt;BR&gt;&lt;/STRONG&gt;Private Sub btnLogin_Click(ByVal sender As System.Object, _&lt;BR&gt;&amp;nbsp; ByVal e As System.Windows.RoutedEventArgs)&lt;BR&gt;&amp;nbsp; DialogResult = True&lt;BR&gt;&amp;nbsp; Me.Close()&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Displaying the Login Screen&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;At some point when your application launches, you will need to display your login screen modally. Below is the code that you would call to display the login form (named frmLogin in my sample application). This code is called from the main application form, and thus the owner of the login screen is set to “this”. You then call the ShowDialog method on the login screen to have this form displayed modally. After the user clicks on one of the two buttons you need to check to see what the DialogResult property was set to. The DialogResult property is a nullable type and thus you first need to check to see if the value has been set.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;C#&lt;BR&gt;&lt;/STRONG&gt;private void DisplayLoginScreen()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; frmLogin frm = new frmLogin();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; frm.Owner = this;&lt;BR&gt;&amp;nbsp; frm.ShowDialog();&lt;BR&gt;&amp;nbsp; if (frm.DialogResult.HasValue &amp;amp;&amp;amp; frm.DialogResult.Value)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("User Logged In");&lt;BR&gt;&amp;nbsp; else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Close();&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Visual Basic&lt;BR&gt;&lt;/STRONG&gt;Private Sub DisplayLoginScreen()&lt;BR&gt;&amp;nbsp; Dim frm As New frmLogin()&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; frm.Owner = Me&lt;BR&gt;&amp;nbsp; frm.ShowDialog()&lt;BR&gt;&amp;nbsp; If frm.DialogResult.HasValue And frm.DialogResult.Value Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MessageBox.Show("User Logged In")&lt;BR&gt;&amp;nbsp; Else&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.Close()&lt;BR&gt;&amp;nbsp; End If&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Creating a nice looking login screen is fairly simple to do in WPF. Using the DropShadowEffect can add a nice finished look to not only your form, but images and buttons as well. Using a border-less window is a great way to give a custom look to a login screen or splash screen. The DialogResult property on WPF Windows allows you to communicate back to the calling routine what happened on the modal screen. I hope this article gave you some ideas on how to create a login screen in WPF.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;NOTE: You can download the complete sample code&amp;nbsp;at my website. &lt;A href="http://www.pdsa.com/downloads"&gt;http://www.pdsa.com/downloads&lt;/A&gt;. Choose Tips &amp;amp; Tricks, then "WPF Login Screen" from the drop-down.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7241117" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/WPF/default.aspx">WPF</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/10/27/create-a-login-window-in-wpf.aspx</feedburner:origLink></item><item><title>Binding to Config Settings in WPF</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/IE28xd5o8fE/binding-to-config-settings-in-wpf.aspx</link><pubDate>Tue, 20 Oct 2009 02:49:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7233456</guid><dc:creator>psheriff</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7233456</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/10/19/binding-to-config-settings-in-wpf.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Almost every application has a configuration file used to store global settings. What would be cool is to have a global settings class that reads this data from the .Config file, then can be used to bind to UI elements within your WPF application. This is actually very easy to accomplish using the data-binding features in WPF.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Creating a Config Class&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Below is a sample App.Config file you might add to a WPF application with a couple of settings in the &amp;lt;appSettings&amp;gt; element in the file.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;configuration&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;appSettings&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add key="DefaultState" value="CA"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add key="IsActiveFlag" value="true"/&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/appSettings&amp;gt;&lt;BR&gt;&amp;lt;/configuration&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;These two values might be used as defaults to feed UI elements in your WPF application. So, you now need to create a class that will read these values from the .Config file. Below is a class named MySettings that has two properties; DefaultState and IsActiveFlag. In each of the Get methods is a call to the ConfigurationManager.AppSettings property to retrieve the appropriate element from the .Config file.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;public class MySettings&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; public MySettings()&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; public string DefaultState&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; get {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ConfigurationManager.AppSettings&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ["DefaultState"].ToString();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; public bool IsActiveFlag&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; get {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return Convert.ToBoolean(ConfigurationManager.AppSettings&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ["IsActiveFlag"]);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; public void Refresh()&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ConfigurationManager.RefreshSection("appSettings");&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Public Class MySettings&lt;BR&gt;&amp;nbsp; Public ReadOnly Property DefaultState() As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ConfigurationManager.AppSettings("DefaultState").ToString()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;BR&gt;&amp;nbsp; End Property&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; Public ReadOnly Property IsActiveFlag() As Boolean&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return Convert.ToBoolean( _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ConfigurationManager.AppSettings("IsActiveFlag"))&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;BR&gt;&amp;nbsp; End Property&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; Public Sub Refresh()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ConfigurationManager.RefreshSection("appSettings")&lt;BR&gt;&amp;nbsp; End Sub&lt;BR&gt;End Class&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now, you need to create an instance of this class in your WPF application and bind each property to a UI element.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Create Instance of Config Settings Class&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Open your App.xaml or Application.xaml file and add a new namespace at the top that references your Namespace or application name. In my sample, I created a WPF application called WPFBindConfigSettings, so that is the name that I need to reference as shown in the code below.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;Application x:Class="WPFBindConfigSettings.App"&lt;BR&gt;&amp;nbsp;xmlns="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/A&gt;"&lt;BR&gt;&amp;nbsp;xmlns:x="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/A&gt;"&lt;BR&gt;&amp;nbsp;xmlns:src="clr-namespace:WPFBindConfigSettings"&lt;BR&gt;&amp;nbsp;StartupUri="frmBindSettings.xaml"&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Application.Resources&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ObjectDataProvider x:Key="odpSettings"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ObjectType="{x:Type src:MySettings}" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Application.Resources&amp;gt;&lt;BR&gt;&amp;lt;/Application&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;In the &amp;lt;Application.Resources&amp;gt; element you will add a &amp;lt;ObjectDataProvider&amp;gt; element that will create an instance of your MySettings class. As you can see in the above code that this is as simple as setting the ObjectType attribute in the ObjectDataProvider to src:MySettings. Set the&amp;nbsp; Key attribute for this ObjectDataProvider object to “odpSettings” as you will need to reference this resource from any window you create in your WPF application.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Bind to WPF UI&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now, let’s use this ObjectDataProvider to bind the values from the MySettings class to UI elements on a WPF Window as shown in Figure 1.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 304px; HEIGHT: 204px" title="Binding to UI" alt="Binding to UI" src="http://www.pdsa.com/Images/BindingUI.jpg" width=304 height=204 mce_src="http://www.pdsa.com/Images/BindingUI.jpg"&gt;&lt;BR&gt;Figure 1: You can bind settings from a Config&lt;/P&gt;
&lt;P mce_keep="true"&gt;Below is the XAML to create the form shown in Figure 1.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;lt;Grid&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;StackPanel&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;StackPanel Orientation="Horizontal"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Label&amp;gt;Default State&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBox Name="txtDefaultState"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Width="50"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text="{Binding Source={StaticResource odpSettings},&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Path=DefaultState, Mode=OneWay}"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/TextBox&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;StackPanel Orientation="Horizontal"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Label&amp;gt;Is Active Flag?&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;CheckBox Name="chkIsActiveFlag"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IsChecked="{Binding Source={StaticResource&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; odpSettings}, Path=IsActiveFlag, &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Mode=OneWay}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VerticalAlignment="Center"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/CheckBox&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button Name="btnRefresh"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Click="btnRefresh_Click"&amp;gt;Refresh&amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;BR&gt;&amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;In the above code you use the {Binding} syntax to read the values from the resource named “odpSettings” which is the Key value you created for the ObjectDataProvider in the App.xaml file. You must set the Mode=OneWay since the properties are read-only in the MySettings class. That is all there is to binding to the settings contained in the .Config file.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Refreshing the Config Settings&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;If you modify the values in the .Config file you will want to refresh the values in the ObjectDataProvider and ultimately in the UI. This can be easily accomplished with just a little bit of VB or C# code. Notice the Refresh method in the MySettings class presented above. The Refresh method in the MySettings class calls the ConfigurationManager.RefreshSection method to re-read a section in a .Config file. After refreshing the values from the .Config file you will want to have the UI be updated as well. You can accomplish this in a few different ways.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Refresh each individual control (this approach takes the most code)&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Refresh the ObjectDataProvider which automatically refreshes the controls&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV mce_keep="true"&gt;Implement the INotifyPropertyChanged interface. This is the best method to use&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P mce_keep="true"&gt;Let’s now take a look at each of these three approaches.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Refresh Each Individual Control&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The first method is to refresh each individual control after calling the Refresh method on the MySettings class. This involves getting a reference to the MySettings instance in the ObjectDataProvider class. You can retrieve an instance of the ObjectDataProvider by calling the FindResource method on an instance of the current application. This is done in the source code shown in the following listing. Once you have the reference to the ObjectDataProvider you can grab an instance of the MySettings class and call the Refresh method on that object. This will cause the class to refresh the settings from the changed .Config file.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;private void RefreshControls()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; MySettings opts = (MySettings)((ObjectDataProvider)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Current.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindResource("odpSettings")).ObjectInstance;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; opts.Refresh();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; txtDefaultState.GetBindingExpression(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TextBox.TextProperty).UpdateTarget();&lt;BR&gt;&amp;nbsp; chkIsActiveFlag.GetBindingExpression(&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CheckBox.IsCheckedProperty).UpdateTarget();&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Private Sub RefreshControls()&lt;BR&gt;&amp;nbsp; Dim opts As MySettings = DirectCast(DirectCast( _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Current.FindResource("odpSettings"), _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ObjectDataProvider).ObjectInstance, MySettings)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; opts.Refresh()&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; txtDefaultState.GetBindingExpression( _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TextBox.TextProperty).UpdateTarget()&lt;BR&gt;&amp;nbsp; chkIsActiveFlag.GetBindingExpression( _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CheckBox.IsCheckedProperty).UpdateTarget()&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;Next, you can update the target of the bindings of each control by using the GetBindingExpression method on the specific property on the control and then calling the UpdateTarget method on that property. This will force the control to refresh its binding.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Refresh the Data Provider&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The second method you can use to refresh the data on the UI is to tell the ObjectDataProvider object to call its Refresh method. Again you need to get the instance of the ObjectDataProvider from the Application.Current property and call its FindResource method. You then get a reference to the MySettings object and call its Refresh method. Next, call the Refresh method on the ObjectDataProvider instance. This automatically refreshes all UI elements that are bound to this ObjectDataProvider.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;private void RefreshDataProvider()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; ObjectDataProvider dp = &lt;BR&gt;&amp;nbsp; (ObjectDataProvider)Application.Current.&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FindResource("odpSettings");&lt;BR&gt;&amp;nbsp; MySettings opts = (MySettings)dp.ObjectInstance;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; opts.Refresh();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dp.Refresh();&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Private Sub RefreshDataProvider()&lt;BR&gt;&amp;nbsp; Dim dp As ObjectDataProvider = _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DirectCast(Application.Current.FindResource("odpSettings"), _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ObjectDataProvider)&lt;BR&gt;&amp;nbsp; Dim opts As MySettings = DirectCast(dp.ObjectInstance, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MySettings)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; opts.Refresh()&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dp.Refresh()&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Implement INotifyPropertyChanged&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The third method you can use to refresh the data on the UI is to implement the INotifyPropertyChanged event on the MySettings class. When you implement this interface, you write code that will inform any data bindings that the property, or properties, on a class have changed.&lt;/P&gt;
&lt;P mce_keep="true"&gt;You will modify the MySettings class in order to implement this interface. First off, you will need to import the System.ComponentModel namespace.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;using System.ComponentModel;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Imports System.ComponentModel&lt;/P&gt;
&lt;P mce_keep="true"&gt;Next, change the class definition to implement the interface.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;public class MySettings : INotifyPropertyChanged&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Public Class MySettings&lt;BR&gt;&amp;nbsp; Implements INotifyPropertyChanged&lt;/P&gt;
&lt;P mce_keep="true"&gt;Next you declare your intention to use the PropertyChangedEventHandler event procedure. To make it easier to call this from within the class, it is a good idea to create a method to raise this event. Below is code that needs to be added to the MySettings class.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;public event PropertyChangedEventHandler PropertyChanged;&lt;/P&gt;
&lt;P mce_keep="true"&gt;protected void RaisePropertyChanged(string propertyName)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; var handler = PropertyChanged;&lt;BR&gt;&amp;nbsp; if (handler != null)&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; handler(this, new PropertyChangedEventArgs(propertyName));&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Public Event PropertyChanged(ByVal sender As Object, _&lt;BR&gt;&amp;nbsp; ByVal e As System.ComponentModel.PropertyChangedEventArgs)&amp;nbsp; _&lt;BR&gt;&amp;nbsp; Implements System.ComponentModel. _ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INotifyPropertyChanged.PropertyChanged&lt;/P&gt;
&lt;P mce_keep="true"&gt;Protected Sub RaisePropertyChanged(ByVal propertyName As String)&lt;BR&gt;&amp;nbsp; RaiseEvent PropertyChanged(Me, _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; New PropertyChangedEventArgs(propertyName))&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;The code above takes care of notifying all bound objects about any changes to any properties in this class. Of course, it is up to you from within the class to call the RaisePropertyChanged method anytime you change the values from within the class. This means you need to change the Refresh method in the MySettings class to call the RaisePropertyChanged method.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;public void Refresh()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; ConfigurationManager.RefreshSection("appSettings");&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; RaisePropertyChanged("DefaultState");&lt;BR&gt;&amp;nbsp; RaisePropertyChanged("IsActiveFlag");&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Public Sub Refresh()&lt;BR&gt;&amp;nbsp; ConfigurationManager.RefreshSection("appSettings")&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; RaisePropertyChanged("DefaultState")&lt;BR&gt;&amp;nbsp; RaisePropertyChanged("IsActiveFlag")&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;The lines in bold are used to raise the PropertyChanged event so all bound objects to these properties are notified. Now you can call the following method in the Refresh button’s click event procedure in the WPF window.&lt;/P&gt;
&lt;P mce_keep="true"&gt;C#&lt;BR&gt;private void RefreshINotify()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; MySettings opts = (MySettings)((ObjectDataProvider)&lt;BR&gt;&amp;nbsp;&amp;nbsp; Application.Current.FindResource("odpSettings")).ObjectInstance;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; opts.Refresh();&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;Visual Basic&lt;BR&gt;Private Sub RefreshINotify()&lt;BR&gt;&amp;nbsp; Dim opts As MySettings = _ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DirectCast(DirectCast( _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Application.Current.FindResource("odpSettings"), _&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ObjectDataProvider).ObjectInstance, MySettings)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; opts.Refresh()&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P mce_keep="true"&gt;If you now run this sample and modify the .Config file and click the Refresh button, you will see the change made.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;The data binding features of WPF are useful for more than just binding to database data. In this article you discovered how you can use the binding features to bind .Config file data to UI elements and how to refresh that data when the .Config file changes. You should use the INotifyPropertyChanged interface in most of the classes you create as this will make data binding to UI notifications almost automatic.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;Download the Complete Sample&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;We have the completed sample for this article available on our website at &lt;A href="http://www.pdsa.com/Downloads"&gt;http://www.pdsa.com/Downloads&lt;/A&gt;. Once there, select “&lt;STRONG&gt;Tips and Tricks&lt;/STRONG&gt;” from the Category drop-down. Then select “&lt;STRONG&gt;WPF Sample – Bind Config Settings&lt;/STRONG&gt;” from the Item drop-down.&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7233456" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/WPF/default.aspx">WPF</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/10/19/binding-to-config-settings-in-wpf.aspx</feedburner:origLink></item><item><title>Creating Border-less Windows in WPF</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/Rv3s6v9ZyLE/creating-border-less-windows-in-wpf.aspx</link><pubDate>Mon, 12 Oct 2009 14:24:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7227946</guid><dc:creator>psheriff</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7227946</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/10/12/creating-border-less-windows-in-wpf.aspx#comments</comments><description>&lt;P&gt;When creating a splash screen or to just have a different look for the windows in your WPF application, you might wish to eliminate the border to give it a custom look (see Figure 1). This can be done very easily with WPF.&lt;/P&gt;&lt;IMG alt="No Border Image" src="http://www.pdsa.com/Images/WPFNoBorder.jpg" mce_src="http://www.pdsa.com/Images/WPFNoBorder.jpg"&gt; 
&lt;P&gt;Figure 1: A WPF window that has no border.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Setting Window Attributes&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;To get a border-less window, you need to set the following attributes on your Window.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;WindowStyle="None"&lt;/LI&gt;
&lt;LI&gt;ShowInTaskbar="False"&lt;/LI&gt;
&lt;LI&gt;AllowsTransparency="True"&lt;/LI&gt;
&lt;LI&gt;Background="Transparent"&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;The WindowStyle attribute normally allows you to set a single border, three-D border, or a Tool Window border. Setting this attribute to None will eliminate the border. The ShowInTaskbar attribute is optional, but if you are doing a splash screen you probably won’t want this window to show up in the Task Bar as it is only going to be there for a very short time. The next two attributes, AllowsTransparency and Background work together. You must set AllowsTransparency to True to allow the Background to be set to Transparent. If you do not set these two attributes, then your border will still show up.&lt;/P&gt;
&lt;P&gt;The complete XAML code for the Window shown in Figure 1 looks like the following:&lt;/P&gt;
&lt;P&gt;&amp;lt;Window x:Class="WPFExtras.frmWindowNoBorder"&lt;BR&gt;&amp;nbsp; xmlns="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml/presentation" mce_href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/A&gt;"&lt;BR&gt;&amp;nbsp; xmlns:x="&lt;A href="http://schemas.microsoft.com/winfx/2006/xaml" mce_href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/A&gt;"&lt;BR&gt;&amp;nbsp; WindowStyle="None"&lt;BR&gt;&amp;nbsp; ResizeMode="NoResize"&lt;BR&gt;&amp;nbsp; ShowInTaskbar="False"&lt;BR&gt;&amp;nbsp; AllowsTransparency="True"&lt;BR&gt;&amp;nbsp; Background="Transparent"&lt;BR&gt;&amp;nbsp; WindowStartupLocation="CenterScreen"&lt;BR&gt;&amp;nbsp; Height="300"&lt;BR&gt;&amp;nbsp; Width="300"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Creates the shadow on the right and bottom --&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Border BorderBrush="Gray"&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BorderThickness="0,0,2,2"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CornerRadius="10"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Background="Beige"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Create space between shadow and the next border --&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Border BorderBrush="Transparent"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BorderThickness="5"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CornerRadius="10"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- The inner border --&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Border BorderBrush="Black"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BorderThickness="1.5"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CornerRadius="10"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;StackPanel VerticalAlignment="Bottom" Margin="10"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button Style="{StaticResource BasicControl}"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Click="Button_Click"&amp;gt;Close Me&amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Border&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Border&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Border&amp;gt;&lt;BR&gt;&amp;lt;/Window&amp;gt;&lt;/P&gt;
&lt;P&gt;The XAML code for this Window uses 3 &amp;lt;Border&amp;gt; elements to create the shadow effect. The outer border is the shadow border that displays just on the right and the bottom. This is accomplished by setting the BorderThickness attribute to 0,0,2,2. The next border is to just give some space between the outer “shadow” border and the inner border. Notice the use of the CornerRadius attribute to give a nice rounded border effect.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Creating a border-less window is a very straight-forward process in WPF. Just by setting a few attributes will remove the border. Then you can create your own border by using the &amp;lt;Border&amp;gt; element. Or you could use any type of container you want to contain the controls on your Window.&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7227946" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/WPF/default.aspx">WPF</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/10/12/creating-border-less-windows-in-wpf.aspx</feedburner:origLink></item><item><title>Using a WPF StackPanel for Business Forms</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/0rHj-oDgjC0/using-a-wpf-stackpanel-for-business-forms.aspx</link><pubDate>Wed, 30 Sep 2009 18:27:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7220568</guid><dc:creator>psheriff</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7220568</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/09/30/using-a-wpf-stackpanel-for-business-forms.aspx#comments</comments><description>&lt;P&gt;In WPF if you want to layout a typical business form like the one shown in Figure 1, most people would use a Grid control with rows and columns. However, you may also use a StackPanel control. While sometimes you might need the re-sizing capabilities of a Grid, you sometimes just need a fixed size. For a fixed-size form a StackPanel control can be a little easier and offers a little more flexibility.&lt;/P&gt;
&lt;P&gt;&lt;IMG style="WIDTH: 354px; HEIGHT: 204px" title="StackPanel Layout" border=0 alt="StackPanel Layout" src="http://www.pdsa.com/Images/StackPanelLayout.jpg" width=354 height=204 mce_src="http://www.pdsa.com/Images/StackPanelLayout.jpg"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Figure 1: A business form using a StackPanel&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Using a Grid&lt;BR&gt;&lt;/STRONG&gt;If you were to layout the above form using a Grid control you might write code that looks like the following:&lt;/P&gt;
&lt;P&gt;&amp;lt;Grid&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid.ColumnDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ColumnDefinition /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Grid.ColumnDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Grid.RowDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition Height="Auto" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition Height="Auto" /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RowDefinition Height="Auto" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Grid.RowDefinitions&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Label&amp;nbsp;&amp;nbsp; Grid.Column="0" Grid.Row="0"&amp;gt;FirstName&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;TextBox Grid.Column="1" Grid.Row="0" Name="txtFirst" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Label&amp;nbsp;&amp;nbsp; Grid.Column="0" Grid.Row="1"&amp;gt;Last Name&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;TextBox Grid.Column="1" Grid.Row="1" Name="txtLast" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Button&amp;nbsp; Grid.Column="1" Grid.Row="2" Name="btnClose"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Close&lt;BR&gt;&amp;nbsp; &amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P&gt;In the above XAML code you need to assign the Grid.Row and a Grid.Column properties on each Label, TextBox and Button control. This is how the XAML knows where to place each control in the Grid.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Using a StackPanel Control&lt;BR&gt;&lt;/STRONG&gt;Now, let’s layout the same form using a series of StackPanel controls. Each StackPanel for each “row” will have the Orientation set to “Horizontal”. There will also be a Style setup for each Label to set the Width property to a specific amount so each text box will be aligned correctly. Below is what the form that uses the StackPanel looks like.&lt;/P&gt;
&lt;P&gt;&amp;lt;StackPanel&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;StackPanel Orientation="Horizontal"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Label&amp;gt;First Name&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBox Name="txtFirst"&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;StackPanel Orientation="Horizontal"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Label&amp;gt;Last Name&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBox Name="txtLast"&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;StackPanel Orientation="Horizontal"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Label&amp;gt;&amp;lt;/Label&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button Name="btnClose"&amp;gt;Close&amp;lt;/Button&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;BR&gt;&amp;lt;/StackPanel&amp;gt;&lt;/P&gt;
&lt;P&gt;Now here are the styles that you add to the Window.Resources on this window to give the form its structure.&lt;/P&gt;
&lt;P&gt;&amp;lt;Window.Resources&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Style TargetType="Label"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="Width" Value="100" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;Style TargetType="TextBox"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="MinWidth" Value="160" /&amp;gt;&lt;BR&gt;&amp;nbsp; &amp;lt;/Style&amp;gt;&lt;BR&gt;&amp;lt;/Window.Resources&amp;gt;&lt;/P&gt;
&lt;P&gt;Now, there are advantages and disadvantages to using a Grid and to using a StackPanel. A Grid is great because the text box controls will automatically re-size as the user sizes the form. However, if you have several rows and you wish to insert a row in the middle, you need to renumber each row after the new row. Sometimes the VS.NET designer will renumber them for you, but sometimes it won’t. Or, if you wish to move an existing row below or above another, you will also be doing a lot of manual renumbering.&lt;/P&gt;
&lt;P&gt;Many business forms do not require re-sizing, so in this case a StackPanel works very well. Using styles gives you the same flexibility as the Grid column definitions, so this is very nice. Also, the ability to just move rows around without worrying about renumbering is a great benefit. However, you do lose the re-sizing capabilities, so this is a tradeoff.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;BR&gt;As with most WPF applications, there are typically more ways than one to accomplish the same thing. This is probably the most frustrating part of learning WPF. Here I showed you a couple different ways to layout the same business form. Each method has its advantages and disadvantages, so it will be up to you to determine when to use each method.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7220568" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/WPF/default.aspx">WPF</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/09/30/using-a-wpf-stackpanel-for-business-forms.aspx</feedburner:origLink></item><item><title>Split Name into First and Last</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/yTjOulnix1U/split-name-into-first-and-last.aspx</link><pubDate>Mon, 21 Sep 2009 18:04:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7213434</guid><dc:creator>psheriff</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7213434</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/09/21/split-name-into-first-and-last.aspx#comments</comments><description>&lt;P&gt;Not too long ago we received a text file of customer names. The problem with the file is it just had one field "Name". One of the requirements of our database application was to have a first name field and a last name field so our customer could search for their customers on either field. As a result we needed to take this text file and split out the data into the two fields from the one.&lt;/P&gt;
&lt;P&gt;As we looked into this file, we noticed that the data was in complete disarray! Some of the names were entered like "First Last", and some in the format "Last, First". So, we needed to perform a little string parsing to get the data into our database table. The following is a simplified version of the routine we wrote to attempt to handle each format and create a new Customer object that we could then use to populate our database table. &lt;/P&gt;
&lt;P&gt;First we needed to create a Customer class. We created an instance of this Customer class and passed in the "name" value read from the text file into the method of the Customer class named NameSplit(). &lt;/P&gt;
&lt;P&gt;C#&lt;BR&gt;class Customer&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; public string FirstName { get; set; }&lt;BR&gt;&amp;nbsp; public string LastName { get; set; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp; public void NameSplit(string name)&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(name.Length &amp;gt; 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Check for a comma&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(name.IndexOf(",") &amp;gt; 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LastName = name.Substring(0, name.IndexOf(",")).Trim();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FirstName = name.Substring(name.IndexOf(",") + 1).Trim();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if(name.IndexOf(" ") &amp;gt; 0)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FirstName = name.Substring(0, name.IndexOf(" ")).Trim();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LastName = name.Substring(name.IndexOf(" ") + 1).Trim();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Visual Basic&lt;BR&gt;Public Class Customer&lt;BR&gt;&amp;nbsp; Private mFirstName As String&lt;BR&gt;&amp;nbsp; Private mLastName As String&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Public Property FirstName() As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return mFirstName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set(ByVal Value As String)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mFirstName = Value&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Set&lt;BR&gt;&amp;nbsp; End Property&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Public Property LastName() As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return mLastName&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set(ByVal Value As String)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mLastName = Value&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Set&lt;BR&gt;&amp;nbsp; End Property&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Public Sub NameSplit(ByVal name As String)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If name.Length &amp;gt; 0 Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' First check for a comma to see if they entered Last, First&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If name.IndexOf(",") &amp;gt; 0 Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mLastName = name.Substring(0, name.IndexOf(",")).Trim()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mFirstName = name.Substring(name.IndexOf(",") + 1).Trim()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf name.IndexOf(" ") &amp;gt; 0 Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mFirstName = name.Substring(0, name.LastIndexOf(" ")).Trim()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mLastName = name.Substring(name.LastIndexOf(" ") + 1).Trim()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp; End Sub&lt;BR&gt;End Class&lt;/P&gt;
&lt;P&gt;To test out this method, use the following code:&lt;/P&gt;
&lt;P&gt;C#&lt;BR&gt;private void TestCustomerSplit()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; Customer cust;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; cust = new Customer();&lt;BR&gt;&amp;nbsp; cust.NameSplit("Bruce Jones");&lt;BR&gt;&amp;nbsp; MessageBox.Show(cust.FirstName + " " + cust.LastName);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; cust = new Customer();&lt;BR&gt;&amp;nbsp; cust.NameSplit("Jones, Bruce");&lt;BR&gt;&amp;nbsp; MessageBox.Show(cust.FirstName + " " + cust.LastName);&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Visual Basic&lt;BR&gt;Private Sub TestCustomerSplit()&lt;BR&gt;&amp;nbsp; Dim cust As Customer&lt;/P&gt;
&lt;P&gt;&amp;nbsp; cust = New Customer()&lt;BR&gt;&amp;nbsp; cust.NameSplit("Bruce Jones")&lt;BR&gt;&amp;nbsp; MessageBox.Show(cust.FirstName &amp;amp; " " &amp;amp; cust.LastName)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; cust = New Customer()&lt;BR&gt;&amp;nbsp; cust.NameSplit("Jones, Bruce")&lt;BR&gt;&amp;nbsp; MessageBox.Show(cust.FirstName &amp;amp; " " &amp;amp; cust.LastName)&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P&gt;Another way to accomplish this task would have been to use the Split() method of the String class. You can split a string on a specific character like a space or a comma. You then end up with an array of each name. I will leave that as an exercise for you to do! :)&lt;/P&gt;
&lt;P&gt;You just have to love the string parsing capabilities of .NET! Just a little bit of code was all it took to make this job of turning different formats into something that was much easier to work with.&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7213434" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/String+Parsing/default.aspx">String Parsing</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/09/21/split-name-into-first-and-last.aspx</feedburner:origLink></item><item><title>Date Handling Tip Part 2: Get the Month Name as Extension Method</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/5SSezV1Wvw0/date-handling-tip-part-2-get-the-month-name-as-extension-method.aspx</link><pubDate>Thu, 17 Sep 2009 16:31:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7209452</guid><dc:creator>psheriff</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7209452</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/09/17/date-handling-tip-part-2-get-the-month-name-as-extension-method.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;After my last post on the GetMonthName, I had a question on how to add this method to the DateTime class as an Extension method. I thought this would make a good follow-up, so here is how you can accomplish this.&lt;/P&gt;
&lt;P mce_keep="true"&gt;First, let's do the C# extension method. Add a new class to your project. For this example, I called the class "MyExtensions". This class needs to be defined as a static class. Next add a public method called GetMonthName. This is a static method and accepts a DateTime object as a parameter. Remember that with Extension methods you need to use the keyword "this" in front of the parameter. Below is the C# example:&lt;/P&gt;
&lt;P mce_keep="true"&gt;public static class MyExtensions&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; public static string GetMonthName(this DateTime dateValue)&lt;BR&gt;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateTimeFormatInfo info = new DateTimeFormatInfo();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return info.MonthNames[dateValue.Month - 1];&lt;BR&gt;&amp;nbsp; }&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;To use this extension method you can write code like the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;DateTime value;&lt;/P&gt;
&lt;P mce_keep="true"&gt;value = DateTime.Now;&lt;/P&gt;
&lt;P mce_keep="true"&gt;MessageBox.Show(value.GetMonthName());&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now, let's take a look at how to accomplish the same thing in Visual Basic. With Visual Basic there is no such thing as a Shared class, so instead you use a Module. So, we add a module to our project called "MyExtensions" to our project. You have to import the System.Runtime.CompilerServices namespace as we will be attaching an Attribute to our extension method. Below is what our new module now looks like.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Imports System.Runtime.CompilerServices&lt;BR&gt;Imports System.Globalization&lt;/P&gt;
&lt;P mce_keep="true"&gt;Module MyExtensions&lt;BR&gt;&amp;nbsp; &amp;lt;Extension()&amp;gt; _&lt;BR&gt;&amp;nbsp; Public Function GetMonthName(ByVal dateValue As Date) As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim info As New DateTimeFormatInfo&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return info.MonthNames(dateValue.Month - 1)&lt;BR&gt;&amp;nbsp; End Function&lt;BR&gt;End Module&lt;/P&gt;
&lt;P mce_keep="true"&gt;Now, to use this new extension method simply write code like the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;Dim value As Date&lt;/P&gt;
&lt;P mce_keep="true"&gt;value = Now&lt;/P&gt;
&lt;P mce_keep="true"&gt;MessageBox.Show(value.GetMonthName())&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog" mce_href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7209452" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/Extension+Methods/default.aspx">Extension Methods</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/09/17/date-handling-tip-part-2-get-the-month-name-as-extension-method.aspx</feedburner:origLink></item><item><title>Date Handling Tip: Get the Month Name</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/PdjQuvh1Tvw/date-handling-tip-get-the-month-name.aspx</link><pubDate>Wed, 16 Sep 2009 20:50:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7208532</guid><dc:creator>psheriff</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7208532</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/09/16/date-handling-tip-get-the-month-name.aspx#comments</comments><description>&lt;P&gt;There are a lot of great date handling methods attached to the DateTime class in .NET. However, if you wish to get information such as the current month name, you will not find it in this class. The reason is because .NET needs to take into account local culture and languages. Thus, methods that return something that is specific to a language or a culture are placed under the System.Globalization namespace. As an example, below is the code you would need to write to return the month name as a string in any language. &lt;/P&gt;
&lt;DIV class=code&gt;VB.NET&lt;BR&gt;Imports System.Globalization&lt;BR&gt;&lt;BR&gt;Public Shared Function GetMonthName(ByVal dateValue As Date) As String&lt;BR&gt;&amp;nbsp;&amp;nbsp;Dim info As New DateTimeFormatInfo&lt;BR&gt;&amp;nbsp;&amp;nbsp;Dim names() As String&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;names = info.MonthNames&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;Return names(dateValue.Month - 1)&lt;BR&gt;End Function&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;Here is the same code in C#: &lt;/P&gt;
&lt;DIV class=code&gt;C#&lt;BR&gt;using System.Globalization;&lt;BR&gt;&lt;BR&gt;public static string GetMonthName(DateTime dateValue)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;DateTimeFormatInfo info = new DateTimeFormatInfo();&lt;BR&gt;&amp;nbsp;&amp;nbsp;string[] names;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;names = info.MonthNames;&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;return names[dateValue.Month - 1];&lt;BR&gt;}&lt;BR&gt;&lt;/DIV&gt;
&lt;P&gt;In the code above, you create an instance of the DateTimeFormatInfo class. This class is located in the System.Globalization namespace. It is this class that has properties for the month names, day names, abbreviated month names, the month separator character and other characteristics of dates that can change with local culture.&lt;/P&gt;
&lt;P&gt;You call the GetMonthName method presented above and pass in any valid date/time value and the month name for that date will be returned. For example, if you were to wrap the above method into a class called MyDates, then you would write code as shown below: &lt;/P&gt;
&lt;DIV class=code&gt;MessageBox.Show(MyDates.GetMonthName(DateTime.Now)); &lt;/DIV&gt;
&lt;P&gt;Now, of course, you do not need to wrap up the calls to the DateTimeFormatInfo as I did here. You can just use the properties and methods of the DateTimeFormatInfo class directly. I presented it as I did above for clarity. You can always just call any of the various properties and methods directly. For example, there is a GetMonthName() method that you can call and just pass in the month number.&lt;/P&gt;
&lt;DIV class=code&gt;DateTimeFormatInfo info = new DateTimeFormatInfo();&lt;BR&gt;&lt;BR&gt;MessageBox.Show(info.GetMonthName(DateTime.Now.Month)); &lt;/DIV&gt;
&lt;P&gt;You can also get any of the day names of the weeks by using the GetDayName() method. &lt;/P&gt;
&lt;DIV class=code&gt;DateTimeFormatInfo info = new DateTimeFormatInfo();&lt;BR&gt;&lt;BR&gt;MessageBox.Show(info.GetDayName(0)); &lt;/DIV&gt;
&lt;P&gt;There is much more to the DateTimeFormatInfo class than I presented here, so take some time and check out all the various methods and properties of this powerful class.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7208532" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/globalization/default.aspx">globalization</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/09/16/date-handling-tip-get-the-month-name.aspx</feedburner:origLink></item><item><title>Check if String is All Lower or All Upper Case</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/b4ElEwXozwY/check-if-string-is-all-lower-or-all-upper-case.aspx</link><pubDate>Fri, 11 Sep 2009 15:09:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7200989</guid><dc:creator>psheriff</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7200989</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/09/11/check-if-string-is-all-lower-or-all-upper-case.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Funny how sometimes there are so many ways to accomplish the same thing. In a project last week I needed to check&amp;nbsp;if a user entered&amp;nbsp;a sentence in all lower (or could have been upper) case. So I immediately went to the most simple solution; using the ToLower() method on the string object and comparing the original string input to the lower version of the same sentence. The code is shown below.&lt;/P&gt;
&lt;P mce_keep="true"&gt;private bool IsAllLowerCase(string value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; return (value.Equals(value.ToLower()));&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;This is a simple method that should be fairly performant. I then started to think that I could also use a regular expression to do this as well. This is shown in the following code:&lt;/P&gt;
&lt;P mce_keep="true"&gt;using System.Text.RegularExpressions;&lt;/P&gt;
&lt;P mce_keep="true"&gt;private bool IsAllLowerCase(string value)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; // Allow anything but upper case&lt;BR&gt;&amp;nbsp; return new Regex(@"^([^A-Z])+$").IsMatch(value);&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;I have seen many fancy, complicated versions of this, but for this situation&amp;nbsp;I wanted to allow any character, number or punctuation, I just do not want upper case characters. This small little Regular Expression does the job quite nicely.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;Here is the same code using the ToLower() method and regular expressions using Visual Basic.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Private Function IsAllLowerCase( _&lt;BR&gt;&amp;nbsp;ByVal value As String) As Boolean&lt;BR&gt;&amp;nbsp;&amp;nbsp; Return (value.Equals(value.ToLower()))&lt;BR&gt;End Function&lt;/P&gt;
&lt;P mce_keep="true"&gt;Imports System.Text.RegularExpressions&lt;/P&gt;
&lt;P mce_keep="true"&gt;Private Function IsAllLowerCase( _&lt;BR&gt;&amp;nbsp;ByVal value As String) As Boolean&lt;BR&gt;&amp;nbsp;&amp;nbsp; Return New Regex("^([^A-Z])+$").IsMatch(value)&lt;BR&gt;End Function&lt;/P&gt;
&lt;P mce_keep="true"&gt;Of course, you can see that you can just flip this around to check to see if a string is all upper case too.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7200989" width="1" height="1"&gt;</description><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/09/11/check-if-string-is-all-lower-or-all-upper-case.aspx</feedburner:origLink></item><item><title>Using The ConnectionStringBuilder class</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/-gvZjmVQmv8/using-the-connectionstringbuilder-class.aspx</link><pubDate>Tue, 08 Sep 2009 15:48:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7196565</guid><dc:creator>psheriff</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7196565</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/09/08/using-the-connectionstringbuilder-class.aspx#comments</comments><description>&lt;P&gt;Building a connection string from scratch can sometimes be a little daunting when you do not know the exact syntax. Of course, you can always visit &lt;A href="http://www.connectionstrings.com/"&gt;www.connectionstrings.com&lt;/A&gt; and find some great help there. In lieu of this you can also use the ConnectionStringBuilder class. Each of the ADO.NET providers supplies a version of this class that will build a connection string for you. Below is an example of how to use this class.&lt;/P&gt;
&lt;P&gt;VB.NET&lt;BR&gt;Imports System.Data.SqlClient&lt;/P&gt;
&lt;P&gt;Private Sub CreateConnectionString()&lt;BR&gt;&amp;nbsp; Dim builder As New SqlConnectionStringBuilder&lt;/P&gt;
&lt;P&gt;&amp;nbsp; builder.DataSource = "(local)"&lt;BR&gt;&amp;nbsp; builder.InitialCatalog = "Northwind"&lt;BR&gt;&amp;nbsp; builder.UserID = "user1"&lt;BR&gt;&amp;nbsp; builder.Password = "&lt;A href="mailto:P@ssw0rd"&gt;P@ssw0rd&lt;/A&gt;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; MessageBox.Show(builder.ConnectionString)&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P&gt;C#&lt;BR&gt;using System.Data.SqlClient;&lt;/P&gt;
&lt;P&gt;private void CreateConnectionString()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; builder.DataSource = "(local)";&lt;BR&gt;&amp;nbsp; builder.InitialCatalog = "Northwind";&lt;BR&gt;&amp;nbsp; builder.UserID = "user1";&lt;BR&gt;&amp;nbsp; builder.Password = "&lt;A href="mailto:P@ssw0rd"&gt;P@ssw0rd&lt;/A&gt;";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; MessageBox.Show(builder.ConnectionString);&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;This is a pretty easy class to use. You can just fill in the basic information such as the DataSource, InitialCatalog, the UserId and Password and it will create a connection string for you. The output from the above code will be: "Data Source=(local);Initial Catalog=Northwind;User ID=user1;Password=p@ssword".&lt;/P&gt;
&lt;P&gt;To add on additional keywords for your connection string you may use the Add method. This method takes the keyword and the value and will add them in the appropriate format to your connection string.&lt;/P&gt;
&lt;P&gt;As mentioned, each ADO.NET data provider supplies one of these classes. For example, if you are using Oracle, you would use the System.Data.OracleClient namespace, then use the OracleConnectionStringBuilder. &lt;/P&gt;
&lt;P&gt;The ConnectionStringBuilder class allows you to parse the individual elements of a connection string and put them into the corresponding properties in the ConnectionStringBuilder. In the following example you take an existing connection string like the one shown in the code below and place it into the ConnectionString property of the ConnectionStringBuilder. The ConnectionStringBuilder will then break it into the appropriate properties.&lt;/P&gt;
&lt;P&gt;VB.NET&lt;BR&gt;Private Sub ParseConnectionString()&lt;BR&gt;&amp;nbsp; Dim cnn As String&lt;BR&gt;&amp;nbsp; Dim builder As New SqlConnectionStringBuilder&lt;/P&gt;
&lt;P&gt;&amp;nbsp; cnn = "Server=Localhost;Initial Catalog=Northwind;User ID=user1;Password=P@ssw0rd"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; builder.ConnectionString = cnn&lt;/P&gt;
&lt;P&gt;&amp;nbsp; MessageBox.Show(builder.DataSource)&lt;BR&gt;&amp;nbsp; MessageBox.Show(builder.InitialCatalog)&lt;BR&gt;&amp;nbsp; MessageBox.Show(builder.UserID)&lt;BR&gt;End Sub&lt;/P&gt;
&lt;P&gt;C#&lt;BR&gt;private void ParseConnectionString()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; string cnn;&lt;BR&gt;&amp;nbsp; SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();&lt;/P&gt;
&lt;P&gt;&amp;nbsp; cnn = "Server=Localhost;Initial Catalog=Northwind;User ID=user1;Password=P@ssw0rd";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; builder.ConnectionString = cnn;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Debug.WriteLine(builder.DataSource);&lt;BR&gt;&amp;nbsp; Debug.WriteLine(builder.InitialCatalog);&lt;BR&gt;&amp;nbsp; Debug.WriteLine(builder.UserID);&lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;So the next time you have a connection string that you wish to extract the elements from, or you need to build a connection string, consider using the ConnectionStringBuilder class. I would not recommend using this in a production application as I can't imagine that the performance would be that great, but for figuring out a connection string, this works great.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7196565" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/ADO.NET/default.aspx">ADO.NET</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/09/08/using-the-connectionstringbuilder-class.aspx</feedburner:origLink></item><item><title>Unit Testing in VS.NET 2008 - Live Meeting Recording</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/YAXK13QORAk/unit-testing-in-vs-net-2008-live-meeting-recording.aspx</link><pubDate>Wed, 02 Sep 2009 16:06:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7189293</guid><dc:creator>psheriff</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7189293</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/09/02/unit-testing-in-vs-net-2008-live-meeting-recording.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Last night I did a live webcast for the Florida .NET User Groups (&lt;A href="http://www.fladotnet.org/"&gt;www.fladotnet.org&lt;/A&gt;) on Unit Testing in VS.NET 2008. If you are interested in viewing this Live Meeting seminar it has been recorded. Details are below:&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Subject: FlaDotNet Online: Build Unit Tests the Easy Way with VS.NET 2008 &lt;BR&gt;Recording URL: &lt;A href="https://www.livemeeting.com/cc/mvp/view"&gt;&lt;FONT color=#0000ff&gt;https://www.livemeeting.com/cc/mvp/view&lt;/FONT&gt;&lt;/A&gt; &lt;BR&gt;Recording ID: NNRDN8 &lt;BR&gt;Attendee Key: F8swp9,WR &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;Enjoy!&lt;BR&gt;Paul Sheriff&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'; FONT-SIZE: 10pt; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'; FONT-SIZE: 7.5pt; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7189293" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/Unit+Testing+.NET/default.aspx">Unit Testing .NET</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/09/02/unit-testing-in-vs-net-2008-live-meeting-recording.aspx</feedburner:origLink></item><item><title>Using Parameters with Dynamic SQL</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/YhAljtMBE4o/using-parameters-with-dynamic-sql.aspx</link><pubDate>Mon, 31 Aug 2009 17:08:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7186595</guid><dc:creator>psheriff</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7186595</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/08/31/using-parameters-with-dynamic-sql.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;Some programming situations require you to use Dynamic SQL. Of course the problem with using Dynamic SQL is that this can lead to SQL Injection attacks. However, you can avoid these problems, by just changing how you submit Dynamic SQL to your back end database.&lt;/P&gt;
&lt;P mce_keep="true"&gt;To illustrate this, consider the sample table of users listed below.&lt;/P&gt;
&lt;P mce_keep="true"&gt;CREATE TABLE User&lt;BR&gt;(&lt;BR&gt;Login char(16) not null primary key,&lt;BR&gt;Password varchar(20) not null&lt;BR&gt;)&lt;BR&gt;go&lt;BR&gt;INSERT INTO User values('PSheriff', 'password')&lt;BR&gt;go&lt;BR&gt;INSERT INTO User values('Keng', 'password')&lt;BR&gt;go &lt;/P&gt;
&lt;P mce_keep="true"&gt;You can copy and paste the above SQL code into your database management system and create this table. After you have created this table, you might create a login screen and use some code like the following to see if the users are in the User table.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;Private Sub BADLoginCode()&lt;BR&gt;&amp;nbsp;Dim sql As String&lt;BR&gt;&amp;nbsp;Dim cmd As SqlClient.SqlCommand&lt;BR&gt;&amp;nbsp;Dim rows As Integer&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;sql = " SELECT Count(*) As TotalRows FROM User "&lt;BR&gt;&amp;nbsp;sql &amp;amp;= " WHERE Login = '" &amp;amp; txtLogin.Text &amp;amp; "'"&lt;BR&gt;&amp;nbsp;sql &amp;amp;= " AND Password = '" &amp;amp; txtPassword.Text &amp;amp; "'"&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;cmd = New SqlClient.SqlCommand(sql)&lt;BR&gt;&amp;nbsp;cmd.Connection = New SqlClient.SqlConnection(AppConfig.ConnectString)&lt;BR&gt;&amp;nbsp;cmd.Connection.Open()&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;rows = Convert.ToInt32(cmd.ExecuteScalar())&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;If rows &amp;gt; 0 Then&lt;BR&gt;&amp;nbsp;&amp;nbsp; MessageBox.Show("Success")&lt;BR&gt;&amp;nbsp;Else&lt;BR&gt;&amp;nbsp;&amp;nbsp; MessageBox.Show("Failure")&lt;BR&gt;&amp;nbsp;End If&lt;BR&gt;End Sub &lt;/P&gt;
&lt;P mce_keep="true"&gt;The problem with the above code is if a hacker where to type in the following into the Login ID field;&lt;/P&gt;
&lt;P mce_keep="true"&gt;' OR 1=1 DELETE FROM Users -- &lt;/P&gt;
&lt;P mce_keep="true"&gt;Then the resulting SQL that is submitted to the back end database is the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;SELECT Count(*) As TotalRows&lt;BR&gt;FROM User&lt;BR&gt;WHERE Login = '' OR 1=1 &lt;BR&gt;DELETE FROM User --' &lt;BR&gt;AND Password = '' &lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;As you can see this will not only allow the user into the application, but will also delete all other users in the system! This is not a good thing.&lt;/P&gt;
&lt;P mce_keep="true"&gt;However, with just a very minor change to this code, you can protect yourself against this type of attack. Just like when calling a stored procedure you use Parameters on the command object to submit the login id and password to the input parameters, you can do the same type of coding with dynamic SQL.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;BR&gt;Private Sub LoginGood()&lt;BR&gt;&amp;nbsp;Dim sql As String&lt;BR&gt;&amp;nbsp;Dim cmd As SqlClient.SqlCommand&lt;BR&gt;&amp;nbsp;Dim rows As Integer&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;sql = " SELECT Count(*) As TotalRows FROM User "&lt;BR&gt;&amp;nbsp;sql &amp;amp;= " WHERE Login = @sLogin "&lt;BR&gt;&amp;nbsp;sql &amp;amp;= " AND Password = @sPassword"&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;cmd = New SqlClient.SqlCommand(sql)&lt;BR&gt;&amp;nbsp;cmd.Connection = New SqlClient.SqlConnection(AppConfig.ConnectString)&lt;BR&gt;&amp;nbsp;cmd.Connection.Open()&lt;BR&gt;&amp;nbsp;cmd.Parameters.Add(New _&lt;BR&gt;&amp;nbsp;&amp;nbsp; SqlClient.SqlParameter("@Login", SqlDbType.Char))&lt;BR&gt;&amp;nbsp;cmd.Parameters.Add(New _&lt;BR&gt;&amp;nbsp;&amp;nbsp; SqlClient.SqlParameter("@Password", SqlDbType.Char))&lt;BR&gt;&amp;nbsp;cmd.Parameters.Item("@Login").Value = txtLogin.Text&lt;BR&gt;&amp;nbsp;cmd.Parameters.Item("@Password").Value = txtPassword.Text&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;rows = Convert.ToInt32(cmd.ExecuteScalar())&lt;BR&gt;&amp;nbsp;If rows &amp;gt; 0 Then&lt;BR&gt;&amp;nbsp;&amp;nbsp; MessageBox.Show("Success")&lt;BR&gt;&amp;nbsp;Else&lt;BR&gt;&amp;nbsp;&amp;nbsp; MessageBox.Show("Failure")&lt;BR&gt;&amp;nbsp;End If&lt;BR&gt;End Sub &lt;/P&gt;
&lt;P mce_keep="true"&gt;Notice the use of the Parameters in the dynamic SQL. When you now run this code, the command object and the parameters ensure that no SQL injection attacks will affect your code.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7186595" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/SQL/default.aspx">SQL</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/Injection+Attack/default.aspx">Injection Attack</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/08/31/using-parameters-with-dynamic-sql.aspx</feedburner:origLink></item><item><title>Cloning a DataRow</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/-vKnkjxPZEY/cloning-a-datarow.aspx</link><pubDate>Thu, 27 Aug 2009 13:56:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7183029</guid><dc:creator>psheriff</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7183029</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/08/27/cloning-a-datarow.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;I can't even tell you how many times over the last few years&amp;nbsp;I have&amp;nbsp;had to clone a row from one DataTable to another DataTable. To make this easier, I created a method that I can call at anytime to create this new DataRow and return a new DataTable back to me. I have another overload of this method that I can also pass in the new DataTable.&amp;nbsp;In ADO.NET there is no easy way to take a single row from an existing DataTable and copy it to another DataTable. The major reason why it is not so easy is you can not add a DataRow that exists in one DataTable to another DataTable. As a result you must create a new DataRow object and copy all of the values from the original DataRow into this new one. You can then create a new DataTable (or use one with the same structure), and add that DataRow to that new DataTable. Below is a method that you can call to accomplish the copying of a single row from one DataTable to a new DataTable.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;C# Code&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;private DataTable CloneDataRow(DataTable dtOld, int rowNumber)&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; DataRow dr;&lt;BR&gt;&amp;nbsp; DataTable dtNew;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dtNew = dtOld.Clone();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dr = dtNew.NewRow();&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dr.ItemArray = dtOld.Rows[rowNumber].ItemArray;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dtNew.Rows.Add(dr);&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; return dtNew;&lt;BR&gt;}&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;VB.NET Code&lt;/STRONG&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Private Function CloneDataRow(ByVal dtOld As DataTable, ByVal rowNumber As Integer) As DataTable&lt;BR&gt;&amp;nbsp; Dim dr As DataRow&lt;BR&gt;&amp;nbsp; Dim dtNew As DataTable&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dtNew = dtOld.Clone()&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dr = dtNew.NewRow()&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dr.ItemArray = dtOld.Rows(rowNumber).ItemArray&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; dtNew.Rows.Add(dr)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; Return dtNew&lt;BR&gt;End Function&lt;/P&gt;
&lt;P mce_keep="true"&gt;I hope&amp;nbsp;you find this method as helpful as I have found it over the years.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P mce_keep="true"&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog" mce_href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;BR&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7183029" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/ADO.NET/default.aspx">ADO.NET</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/08/27/cloning-a-datarow.aspx</feedburner:origLink></item><item><title>About Nothing</title><link>http://feedproxy.google.com/~r/PaulSheriffsOuterCircleBlog/~3/SifzTaDWCYE/about-nothing.aspx</link><pubDate>Wed, 19 Aug 2009 15:43:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7173725</guid><dc:creator>psheriff</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/psheriff/rsscomments.aspx?PostID=7173725</wfw:commentRss><comments>http://weblogs.asp.net/psheriff/archive/2009/08/19/about-nothing.aspx#comments</comments><description>&lt;P&gt;Sometimes in your code you will need to check to see if a value is nothing/null or not. In .NET there are many different ways to check for this condition. It can also be different depending on the language&amp;nbsp;you use. These little differences can really bite you in the a**, so you need to be aware of the differences.&lt;/P&gt;
&lt;P&gt;I&amp;nbsp;like to use the IsNullOrEmpty() method on the string class, so let's take a look at this method using C#.&lt;/P&gt;
&lt;P&gt;private void TestNullOrEmpty()&lt;BR&gt;{&lt;BR&gt;&amp;nbsp; string value;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; //Debug.WriteLine(String.IsNullOrEmpty (value));&amp;nbsp;&amp;nbsp; // NOT VALID&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Value = null;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Debug.WriteLine(String.IsNullOrEmpty(value));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Value = "Hello There";&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Debug.WriteLine(String.IsNullOrEmpty(value));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; if (value != null)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.WriteLine("NOT null");&lt;BR&gt;} &lt;/P&gt;
&lt;P&gt;In C# the first check of the Value variable is not valid since the string has not been initialized.&lt;/P&gt;
&lt;P&gt;In VB.NET you can also use IsNullOrEmpty() method, however, the first check is valid since VB.NET treats this type of error as a warning only. You can change this setting in the Project Settings for your project, so this would be a real error. You can also use the new IsNothing statement to check to see if a value is Not Nothing.&lt;/P&gt;
&lt;P&gt;Private Sub TestNullEmpty()&lt;BR&gt;&amp;nbsp; Dim value As String&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Debug.WriteLine(String.IsNullOrEmpty(value))&lt;/P&gt;
&lt;P&gt;&amp;nbsp; value = Nothing&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Debug.WriteLine(String.IsNullOrEmpty(value))&lt;/P&gt;
&lt;P&gt;&amp;nbsp; value = "Hello There"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Debug.WriteLine(String.IsNullOrEmpty(value))&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If value IsNot Nothing Then&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.WriteLine("NOT Nothing")&lt;BR&gt;&amp;nbsp; End If&lt;BR&gt;End Sub &lt;BR&gt;&lt;/P&gt;
&lt;P&gt;I hope this helps someone in the future when you are moving from one language to another.&lt;/P&gt;
&lt;P&gt;Good Luck With Your Coding,&lt;BR&gt;Paul Sheriff&lt;/P&gt;
&lt;P&gt;** SPECIAL OFFER FOR MY BLOG READERS **&lt;BR&gt;Visit &lt;A href="http://www.pdsa.com/Event/Blog"&gt;http://www.pdsa.com/Event/Blog&lt;/A&gt; for a free eBook on "Fundamentals of N-Tier".&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7173725" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/psheriff/archive/tags/.NET/default.aspx">.NET</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/VB/default.aspx">VB</category><category domain="http://weblogs.asp.net/psheriff/archive/tags/C_2300_/default.aspx">C#</category><feedburner:origLink>http://weblogs.asp.net/psheriff/archive/2009/08/19/about-nothing.aspx</feedburner:origLink></item></channel></rss>
