Tuesday 2 April 2013

What’s New in WPF 4.0



Hi Friends,

In this article i will tell you what's new features added in WPF 4.0.


 New in XAML of .Net  4.0

     • Visual State Manager
     • Touch and Manipulation
     • Graphics and Animations
     • Text
     • Binding
     • WPF and Silver light Designer


New in XAML of .NET 4.0:

1.    Easy Object References with {x:Reference}
2.    Built-in Types
3.    Generics in XAML with {x:TypeArguments}
4.    Support for Arbitrary Dictionary Keys          
5.    Use of Non-Default Constructors with {x:Arguments}
6.    Use of Static Factory Methods with{ x:FactoryMethod}

1: Easy Object References with {x:Reference}


<Label Target="{Binding ElementName=firstName}">FirstName</Label>
<TextBox x:Name="firstName" />

<Label Target="{x:Reference firstName}">FirstName</Label>
<TextBox x:Name="firstName" />

2: Built-in Types

    <x:Int16><x:Int16/>
    <x:Int32><x:Int32/>
    <x:Int64><x:Int64/>
    <x:String> </x:String>
    <x:Object ><x:Object/>
    <x:Boolean><x:Boolean/>
    <x:Char><x:Char/>
    <x:String><x:String/>
    <x:Decimal><x:Decimal/>
    <x:Single><x:Single/>
    <x:Double><x:Double/>
    <x:TimeSpan><x:TimeSpan/>
    <x:Uri><x:Uri/>
    <x:Byte><x:Byte/>
    <x:Array><x:Array/>
    <x:List><x:List/>
    <x:Dictionary> <x:Dictionary/>

3: Generics in XAML with {x:TypeArguments}

<ObservableCollection x:TypeArguments="Employee">
    <l:Employee FirstName="John" Name="Doe" />
    <l:Employee FirstName="Tim" Name="Smith" />
</ObservableCollection />

4: Support for Arbitrary Dictionary Keys:

<StreamGeometry>M 0 0 L 12 8 l 9 12 z
    <x:Key><x:Double>10.0</x:Double></x:Key>
</StreamGeometry>

5: Use of Non-Default Constructors with {x:Arguments}

<DateTime>
    <x:Arguments>
        <x:Int64>1000</x:Int64>
    </x:Arguments>
</DateTime>

6: Use of Static Factory Methods with{ x:FactoryMethod}

               <Guid x:FactoryMethod="Guid.NewGuid" />


New Controls
Three new controls have been added to WPF. These controls are almost 100 percent compatible with the Silver light versions. This enables developers to reuse code and quickly create client and Web versions.
    • Data Grid
    • Calendar
    • Date Picker
Visual State Manager

    • WPF provides better support for changing visual states in a Control Template. The Visual State Manager class and supporting classes have been added so that tools such as Microsoft Expression Blend can be used to define a control's appearance according to its visual state. For example, you can define the appearance of a Button control when it is in the pressed state.
Touch and Manipulation

    • Elements in WPF now accept touch input. The UIElement, and UIElement3D, and Content Element classes expose events that occur when a user touches an element on a touch-enabled screen. In addition to the touch events, the UIElement supports manipulation. A manipulation is interpreted to scale, rotate, or translate the UIElement. For example, a photo viewing application might allow users to move, zoom, resize, and rotate a photo by touching the computer screen over the photo.
Graphics and Animations

Several changes have been made related to graphics and animations.
  • Layout Rounding
    When an object edge falls in the middle of a pixel device, the DPI-independent graphics system can create rendering artifacts, such as blurry or semi-transparent edges. Previous versions of WPF included pixel snapping to help handle this case. Silver light 2 introduced layout rounding, which is another way to move elements so that edges fall on whole pixel boundaries. WPF now supports layout rounding with the UseLayoutRounding attached property on Framework Element.
  • Cached Composition
    By using the new Bitmap Cache and BitmapCacheBrush classes, you can cache a complex part of the visual tree as a bitmap and greatly improve rendering time. The bitmap remains responsive to user input, such as mouse clicks, and you can paint it onto other elements just like any brush.
  • Pixel Shader 3 Support
    WPF 4 builds on top of the ShaderEffect support introduced in WPF 3.5 SP1 by allowing applications to now write effects by using Pixel Shader (PS) version 3.0. The PS 3.0 shader model is more sophisticated than PS 2.0, which allows for even more effects on supported hardware.
  • Easing Functions
    You can enhance animations with easing functions, which give you additional control over the behavior of animations. For example, you can apply an ElasticEase to an animation to give the animation a springy behavior
Text

Several changes have been made related to text.
  • New Text Rendering Stack
    The WPF text rendering stack has been completely replaced. This change brings improvements to text rendering configurability, clarity, and support for international languages. The new text stack now supports explicitly selecting aliased, grayscale, or Clear Type rendering modes. The text stack now supports display-optimized character layout, to produce text with sharpness comparable to Win32/GDI text. The new text stack allows optimizing text hinting and snapping for either animated or static text. The new text stack also supports fonts with embedded bitmaps to be substituted for smaller font sizes, allowing many East Asian fonts to render with sharpness comparable to Win32/GDI text.
  • Selection and Caret Customization
    You can now specify the brush that paints the selection and caret for input and reading controls, such as TextBoxRichTextBox, and FlowDocumentReader. There are two new properties on Textbox Base:
    1. SelectionBrush: allows you to create a brush for highlighting selected text.
    2. CaretBrush: allows you to change the brush that paints the cursor.
Binding

Various changes and enhancements have been made related to binding.
  • Bind to commands on Input Binding.
    You can bind the Command property of an Input Binding class to an instance that is defined in code. The following properties are dependency properties, so that they can be targets of bindings:
    • InputBinding.Command
    • InputBinding.CommandParameter
    • InputBinding.CommandTarget
    • KeyBinding.Key
    • KeyBinding.Modifiers
    • MouseBinding.MouseAction
The Input Binding, Mouse Binding, and Key Binding classes receive data context from the owning Framework Element.
  • Bind to Dynamic Objects
    WPF supports data binding to objects that implement IDynamicMetaObjectProvider. For example, if you create a dynamic object that inherits from Dynamic Object in code, you can use markup extension to bind to the object in XAML. For more information, see the Binding Sources Overview.
  • Bindable Text Run
    Run.Text is now a dependency property. The main advantage is that it now supports one-way bindings. It also supports other features of dependency properties, such as styling and templating.


Happy Programming!!
Don’t forget to leave your feedback and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com     
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
----------------------------------------------------------------------------------

No comments:

Post a Comment