1
2
3
4
5
6

Recreating Simple Windows Forms in WPF and XAML (Part 2)

One of the more obvious issues with the initial post of the dialog XAML code last night was all the hardcoded colors, so this post will be a quick example of how to use defined colors and gradients instead so that when you want to change the colors you don't have to go looking through all the XAML to find where the colors are to modify.

Here is a snippet of the original XAML, specifically the blue gradient header across the top of the dialog and the white text on it:

    <!-- Top Panel (icon, description, help, etc.) -->
    <StackPanel Orientation="Horizontal" Width="500" DockPanel.Dock="Top">
      <StackPanel.Background>
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
          <GradientStop Color="Navy" Offset="0" />
          <GradientStop Color="MidnightBlue" Offset="1" />
        </LinearGradientBrush>    
      </StackPanel.Background> 
      ..
      <TextBlock Width="358" VerticalAlignment="Stretch" Padding="4,4,4,0" 
                 TextWrapping="Wrap" Foreground="White">
      ..
    </StackPanel>

 
The easiest thing to do right off the bat is to just take the LinearGradientBrush definition and move it up to a Resources section you create for the Page (or Window, etc.) - since we are working with a Page we will create a Page.Resources section right under the main Page definition:

  <Page.Resources>
    ..
    <!-- header panel styles -->
    <LinearGradientBrush x:Key="headerPanelFillBrush" StartPoint="0,0" EndPoint="0,1">
      <GradientStop Color="Navy" Offset="0" />
      <GradientStop Color="MidnightBlue" Offset="1" />
    </LinearGradientBrush>
    <SolidColorBrush x:Key="headerTextColor" Color="White" />
    ..
  </Page.Resources>

 
There are two brushes defined in that snippet - the 'headerPanelFillBrush' which is the blue gradient fill in the header, and the 'headerTextColor' which is the white color used for the text - these brushes will be referenced by the value we set for their 'x:Key' tag.

(click 'read more' to read the full article..)

Recreating Simple Windows Forms in WPF and XAML (Part 1)

So after two or three weeks of playing around with WPF/XAML I figured the best place to go next was to try and do some dialogs like I might do today in Windows Forms. I wrote these by hand using the Kaxaml tool mentioned on the recent Scott Hanselman podcast, and if you have that installed you should be able to make use of the .xaml files attached to this post pretty easily.

Keep in mind that this XAML is by hand (with Kaxaml's intellisense), not created via Blend or VS2008, and the XAML is probably atrocious to XAML experts - that's sort of the point. I'll be referring back to this project as I improve it - this post is just the initial post.

A simple dialog

(click 'read more' to read the full article..)

The WPF Journey - Beginning Baby Steps

About a year and a half ago I picked up a copy of Windows Presentation Foundation Unleashed based on a suggestion from a Microsoft rep at a mini code camp they held for businesses in my business sector. I enjoyed the WPF/Silverlight discussion they had, especially since it gave me a chance to ask some questions on the subject, but aside from buying the book I made little actual effort in trying to learn WPF since then.

CodingTags: 

Hello World

What's wrong, title too trite? Maybe I should've gone with "first!" instead? You've found the first post on the site, so make yourself useful and checkout the About page until there is some real content.

This site is in development, but stick around and maybe we can be BFF's. Bookmark now and check back frequently.

CodingTags: