Welcome to MSDN Blogs Sign in | Join | Help

Lester's WPF blog


Simple, easy & beautiful
Composite Application Guidance for WPF 2008

Its been some time before my last post. Just catching my breath with a new addition to my family. :)

The Composite Application Guidance aka PRISM for WPF 2008 has just been released. For those who havent heard of it : "The Composite Application Guidance for WPF can help you split the development of your WPF client application across multiple development teams, each responsible for the development of a piece of the application, and help you seamlessly compose those pieces together into a client application. The guidance includes a reference implementation, reusable library code (called the Composite Application Library), documentation, quick start tutorials and hands-on labs."

For more details/downloads take a  look at the project on codeplex: http://www.codeplex.com/CompositeWPF

Share this post

 

WPF WebBrowser (.NET 3.5 SP1)

One of the new controls is the WebBrowser... aha!! not the Winforms control.. we now have it in WPF.

Functions supported by this control are:

  • NavigateToString
  • NavigateToStream
  • Navigate
  • GoBack
  • GoForward

 In xaml it would look like something like this:

<StackPanel Name="panel">

  <WebBrowser Height="500"  >

  </WebBrowser>

</StackPanel>

 

 

 

I put together a simple sample which tries to use this functionality Looks like the above. Nothing fancy :)

Also since this is beta you might find a few rough edges (bugs) here and there.Please report them on the connect website or on the forums. 

Project Code: Attached

Share this post

 

New 3.5 SP1 features: ScrollViewer.IsDeferredScrollingEnabled; AlternationCount;IEditableCollectionView

3 more features which go hand in hand are the:

·         ScrollViewer.IsDeferredScrollingEnabled

·         AlternationCount

·         IEditableCollectionView

All the above have been used in a sample which looks like this - it supports add/delete/cancel (escape key) operations

 

ScrollViewer.IsDeferredScrollingEnabled

This is an opt in features which provides a perceived performance improvement. What it does is that content doesn’t scroll while the scrollbar is in action. Once you stop the content refreshes to the new scrolled value. In this case you avoid the possible jitter motion in scrolling.

Usage: <ListBox ScrollViewer.IsDeferredScrollingEnabled="true”>               

 

 

Alternation Count

This allows setting alternating properties on rows of an items Control. A lot of our customers have been writing the alternating color of listboxes, listviews,… Now it’s a few lines code which gives you this functionality J

 

Usage:          <Style.Triggers>

            <Trigger Property="ItemsControl.AlternationIndex" Value="0">

              <Setter Property="Background" Value="LightBlue"></Setter>

            </Trigger>

 

            <Trigger Property="ItemsControl.AlternationIndex" Value="1">

              <Setter Property="Background" Value="Maroon"></Setter>

              <Setter Property="Foreground" Value="White"></Setter>

            </Trigger>

          </Style.Triggers>

 

<ListBox AlternationCount="2">                       

 

 

IeditableCollectionView

 

Now with this feature you can easily add/remove/edit items in a collection. Do I hear some shouts of joy

 

The first step is to implement the IEditableObject interface. This requires implementing

·         BeginEdit à store the current value in a temp variable/object

·         CancelEdit à Restore the temp value into the current object

·         EndEdit à clear the temp value

That’s it for your data changes. Now for the operations itself. First you get hold of the IEditiableCollectionView since it exposes the operations.

(IEditableCollectionView)(CollectionViewSource.GetDefaultView(itemsList.Items));

 

This class exposes the following functions

    iecv.AddNew();

    iecv.EditItem();

    iecv.CommitNew();

    iecv.CommitEdit();

    iecv.CancelNew();

    iecv.CancelEdit();

 

 

The code is attached. Have fun.

Share this post

 

GPU based effects

A hot new feature in 3.5 SP1 is GPU based effect. Greg Schechter has has a series of posts on this topic. Its well worth the read. So head over :)

  • GPU-accelerated custom Effects for WPF
  • Using Effects in WPF (Part 2)
  • More details on how Effects work
  • Writing custom GPU-based Effects for WPF
  • A simple Effect sample project and ClickOnce application
  • Writing custom Effects - adding parameters to Effects
  •  


    Video: wpf graphics

    For the full video check out this link

    Share this post

     

    SourceAnalysis: Tool to enforce coding style

    People just love to write code. One tool that is used inside Microsoft is StyleCop which enforces code style guidelines on the code we write. Its always been a ask from customers to get this out and guess what its out!!

    http://code.msdn.microsoft.com/sourceanalysis

    The tool on installation integrates with the VS IDE so the usage is very simple. The rules can be tweaked so that you dont have to follow everything.

     "Specifically, these rules cover the following, in no particular order:

    • Layout of elements, statements, expressions, and query clauses
    • Placement of curly brackets, parenthesis, square brackets, etc
    • Spacing around keywords and operator symbols
    • Line spacing
    • Placement of method parameters within method declarations or method calls
    • Standard ordering of elements within a class
    • Formatting of documentation within element headers and file headers
    • Naming of elements, fields and variables
    • Use of the built-in types
    • Use of access modifiers
    • Allowed contents of files
    • Debugging text

    " Look at the post for more details

    Share this post

     

    Join the WPF Test team

    The WPF test team is hiring. We have the following openings

    ·         Software Development Engineer in Test (see official job posting)

    ·         Software Test Architect (see official job posting)

     For more details check out Ivo’s blog post

     Need some more convincing ... Check the video below :)


    Video: Why Microsoft
    Share this post

     

    WPF 3.5 SP1 feature: StringFormat

    One of the new features in 3.5 SP1 is stringformat. The usage is pretty simple. So following are simple snippets showing its use

    <TextBox Text="{Binding Path=Double, StringFormat=F3}"/>

    <TextBox Text="{Binding Path=Double, StringFormat=Amount: {0:C}}"/>

    <TextBox Text="{Binding Path=Double, StringFormat=Amount: \{0:C\}}"/>

    <TextBox>

      <TextBox.Text>

        <Binding Path="Double" StringFormat="{}{0:C}"/>

      </TextBox.Text>

    </TextBox>

     

    <TextBox>

      <TextBox.Text>

        <MultiBinding StringFormat="{}{0:F2} = {1:D}">

          <Binding Path="Double" />

          <Binding Path="Date"/>

        </MultiBinding>

      </TextBox.Text>

    </TextBox>

    <TextBox>

      <TextBox.Text>

        <Binding Path="Date" StringFormat="{}{0:MM/dd/yyyy}"/>

      </TextBox.Text>

    </TextBox>

    <ListBox Background="Beige" ItemStringFormat="F3">

      <sys:Double>1.11122</sys:Double>

      <sys:Double>2.11345</sys:Double>

    </ListBox>

    <GroupBox Background="AliceBlue" Content="{Binding Path=Double}" ContentStringFormat="F4"

              Header="{Binding Path=Double}" HeaderStringFormat="F5"/>

    <Label Content="{Binding Path=Double}" ContentStringFormat="{}{0:E2}"/>

    <GridView>

      <GridViewColumn Header="Date"

               DisplayMemberBinding="{Binding XPath=Date, StringFormat=D}" />

     This feature makes life a lot more easier when it comes to formatting.. So have fun with it.

    Share this post

     

    .NET 3.5 SP1 - Try it out today

    Have you tried out .NET 3.5 SP1... If not, try it now. Its got loads of new features for WPF. In fact rather than a service pack, its more of a new release ..

    So whats new.. improved deployment, new controls (supports creation of datagrid), improved performance, DirectX integration, HLSL shaders, and many new features.

    For the complete details, take a look at Tims post

    Links to the executables:

    Visual Studio 2008 Service Pack 1 (Beta)

    .NET Framework 3.5 Service Pack 1 (Beta)

    Visual Studio 2008 Express Editions SP1 (Beta)

    Visual Studio 2008 Team Foundation Server 2008 SP1 (Beta)

    MDI task switching sample

    If you are creating apps which have mdi's (multiple document interfaces) you should definitely take a look at Karls post on MDI task switching. Its an elegant solution and  the post explains it nicely ... and yeah you do have the code ...:) .. Take a look

     

     

    Share this post

     

    Clipping of child elements

    On the forums I saw this interesting problem where there was a need to round the corners of a stackpanel inside a border with cornerradius set...

    The top is what you get and the bottom image is what you want. The simplest thing to do here is to set the padding on the border so that the stackpanel doesnt bleed around the corners.

    But when that doesnt meet your requirements you will need to set the clip property on the child in the OnRender function so that you get the correct clipping. The code for the above is attached.(thanks to Ifeanyi)

     

    Share th