Implementation of .NET WPF 4.0 New Features

Today, in this article let's work out on WPF few important and new features that are available in version 4.0. So, some of the features that are going to be discussed in this article are as follows:

  1. Flow Document Reader
     
  2. Data Grid
     
  3. Date Picker
     
  4. Caret Brush
     
  5. Selection Brush

So, rather than studying the lot of theory stuff. Let's today play around with some of these tasks and will try to implement it.

1. Flow Document Reader

This new feature added to version 4.0 enables

The Complete Code of MainWindow.xaml looks like this:

<Window x:Class="WPFFLOWDOCUMENT.MainWindow"
infx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.co
xmlns="http://schemas.microsoft.com/
wm/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<
FlowDocumentReader>
viijay Prativadi's Simple Fl
<FlowDocument>
<
Paragraph TextAlignment="Center" FontFamily="Cambria" FontSize="20">
Vow Document</Paragraph>
h TextAlignment="Center" FontFamily="Cambria" FontSize="18" >This is a Simple Program using WPF</Paragraph>
 
<
Paragraph>
pph FontFamily="Cambria" FontSize="14">
This is a simple article using WPF Flow Document Reader Control. New Feature added to WPF 4.0

</Paragraph>
</
FlowDocument>
</
FlowDocumentReader>

</Grid>
</
Window>

Flow Document.png

2. Data Grid

The Implementation is carried as follows:

The Complete Code of MainWindow.xaml looks like this:

<window x:class="WPFNETFourFeatures.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="MainWindow" height="350"
    width="525" loaded="Window_Loaded">
     <Grid>
      <Expander Header="Show Person Details" HorizontalAlignment="Center" Width="450">
        <DataGrid x:Name="DataGrid1" Width="300" AutoGenerateColumns="False">
           <DataGrid.Columns> <DataGridTextColumn Header="Id" Binding="{Binding Path=Id}">
           </DataGridTextColumn>
           <DataGridTextColumn Header="FirstName" Binding="{Binding Path=FirstName}" Width="100">
           </DataGridTextColumn>
           <DataGridTextColumn Header="LastName" Binding="{Binding Path=LastName}" Width="100">
           </DataGridTextColumn>
           <DataGridTextColumn Header="Age" Binding="{Binding Path=Age}" Width="100">
           </DataGridTextColumn>
           </DataGrid.Columns>
         </DataGrid>
       </Expander>
     </Grid>
</window>


The Complete Code of Person.cs looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WPFNETFourFeatures
{
    class Person
    {
        public int Id
        {
            get; set;
        }
        public string FirstName
        {
            get; set;
        }
        public string LastName
        {
            get; set;
        }
        public int Age
        {
            get; set;
        }
    }
}


The Complete Code of MainWindow.xaml.cs looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPFNETFourFeatures
{
    /// <summary> /// Interaction logic for MainWindow.xaml /// </summary>
 public partial class MainWindow : Window
 {
     public MainWindow()
     {
         InitializeComponent();
     }
     protected void Bind()
     {
         var personlist = new List<Person>
         {
             new Person {Id = 1, FirstName = "Vijay", LastName = "Prativadi", Age = 25}, new Person {Id = 2, FirstName = "Ramesh", LastName = "Kumar", Age = 27}, new Person {Id = 3, FirstName = "Rama", LastName = "Krishna", Age = 24}, new Person {Id = 4, FirstName = "Venkat", LastName = "Reddy", Age = 26}, new Person {Id = 5, FirstName = "Rahul", LastName = "Satelli", Age = 23} };
         DataGrid1.ItemsSource = personlist;
     }
     private void Window_Loaded(object sender, RoutedEventArgs e)
     {
         Bind();
     }
 }
}



DataGrid.png

3. Date Picker

The Implementation is carried as follow

The Complete Code of MainWindow.xaml looks like this:

<Window x:Class="WpfDatePicker.MainWindow"
/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.
xmlns="http://schemas.microsoft.co
mcom/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid x:Name="Grid1">

</Grid>
</
Window>

The Complete Code of MainWindow.xaml.cs looks like this:

using System;
using System.collections.Generic;
using System.CLinq;
using System.Text;
using System.Windows;
using system.windows.Data;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
namespace WpfDatePicker
{
public partial class
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
dt.Select;
}
protected void Bind ()
{
var dt = new DatePicker();
 
selectDate = new DateTime(2011, 12, 27);
dt.DisplayDateStart = new DateTime(2010, 1, 1);
ickerFormat.Long; dt.FirstDayOfWeek = DayOfWeek
dt.DisplayDateEnd = new DateTime(2011, 12, 31);
dt.SelectedDateFormat = Date
P.Monday;
dt.Width = 190;
Grid1.Children.Add(dt);
}
 
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Bind();
}
}
}

DatePicker WPF.png

4. Caret Brush

The Complete Code of MainWindow.xaml looks like this:

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox SelectionBrush="Gray" CaretBrush="Red" SelectionOpacity=".5" Margin="0,0,383,147" Height="27" VerticalAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"> Hello I am WPF App
</TextBox>
</Grid>
 </Window>

CARET Brush.png

5. Selection Brush

This Property Helps to highlight the Selected text.

The Complete Code of MainWindow.xaml looks like this:

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TextBox SelectionBrush="Gray" CaretBrush="Red" SelectionOpacity=".5" Margin="0,0,383,147" Height="27" VerticalAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">

Hello I am WPF App
</TextBox>
</Grid>
</Window>

Selection Brush.png

I hope this article is useful for you.

Up Next
    Ebook Download
    View all
    Learn
    View all
    MVC Corporation is consulting and IT services based company.