Monday, May 30, 2016

Telerik WPF RadGridView Group Header Template customization with ViewModel data

Tools required to execute below sample on your computer
- Visual Studio
- Telerik UI for WPF

Follow the below steps to reproduce this sample
- Create a new WPF Project with Telerik GridView references.
- Create ObjectModel.cs file (Model).
- Create MainWindow.xaml with Codebehind (View).  Note: This comes with WPF Project Visual Sudio Template.
- Create MainWindowViewModel class (ViewModel).

ObjectModel.cs file will contain following classes:
   
   public class CustomerOrder  
   {  
     public Guid    CustomerId { get; set; }  
     public string  FirstName { get; set; }  
     public string  LastName { get; set; }  
     public string  Email { get; set; }  
     public string  PhoneNumber { get; set; }  
     public int     OrderType { get; set; }  
     public int     OrderCost { get; set; }  
   }  
   public class CustomerOrderGrouRow  
   {  
     public CustomerOrderGrouRow()  
     {  
       OrderTypeName = string.Empty;  
     }  
     public Guid   CustomerId { get; set; }  
     public int    OrdersCount { get; set; }  
     public int    OrderType { get; set; }  
     public string OrderTypeName { get; set; }  
     public int    OrderCost { get; set; }  
   }  
   public enum OrderTypes  
   {  
     groceries = 1,  
     Books = 2,  
     Clothes = 3  
   } 
Create MainWindowViewModel with Order Items Observable Collection and fill with some test data. follow the below code
   
    public class MainWindowViewModel : ViewModelBase
    {
        public ObservableCollection OrderItems { get; private set; }

        public MainWindowViewModel()
        {
            var orders = new List
            {
                new CustomerOrder { Email = "Test1@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 1" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 1},
                new CustomerOrder { Email = "Test2@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 2" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 1},
                new CustomerOrder { Email = "Test3@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 3" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 1},
                new CustomerOrder { Email = "Test4@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 4" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 2},
                new CustomerOrder { Email = "Test5@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 5" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 2},
                new CustomerOrder { Email = "Test6@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 6" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 2},
                new CustomerOrder { Email = "Test7@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 7" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 2},
                new CustomerOrder { Email = "Test8@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 8" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 3},
                new CustomerOrder { Email = "Test9@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 9" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 3},
                new CustomerOrder { Email = "Test10@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 10" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 3},
                new CustomerOrder { Email = "Test11@ViewModel.com", PhoneNumber = "1234567890", FirstName = "First Name 11" , LastName = "Last Name 1", CustomerId = Guid.NewGuid(), OrderCost = 95, OrderType = 3},
            };

            var groupOrders = orders
                .GroupBy(i => i.OrderType)
                .Select(i => new CustomerOrderGrouRow
                {
                    OrderType = i.Key,
                    OrdersCount = i.Count(),
                    OrderCost = i.Sum(x => x.OrderCost),
                    CustomerId = i.First().CustomerId,
                    OrderTypeName = GetOrderTypeName(i.Key)
                })
                .ToList();

            var orderItemViewModels = orders
                .Select(i => new CustomerOrderViewModel(i, groupOrders.First(x => x.OrderType == i.OrderType)))
                .ToList();

            OrderItems = new ObservableCollection(orderItemViewModels);
        }

        public string GetOrderTypeName(int orderTypeId)
        {
            switch (orderTypeId)
            {
                case 1:
                    return OrderTypes.groceries.ToString();
                case 2:
                    return OrderTypes.Books.ToString();
                case 3:
                    return OrderTypes.Clothes.ToString();
                default:
                    return string.Empty;
            }
        }
    } 
Now it is time to place the code in MainWindow.xaml file
 <Window x:Class="Customers.MainWindow"  
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
   xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  
   xmlns:customers="clr-namespace:Customers"  
   Title="MainWindow"  
   >  
   <Grid>  
     <telerik:RadGridView  
       Grid.Row="0"  
       Grid.Column="0"  
       AutoExpandGroups="True"  
       AutoGenerateColumns="False"  
       BorderThickness="0 1"  
       CanUserSortColumns="True"  
       GridLinesVisibility="None"  
       IsReadOnly="True"  
       ItemsSource="{Binding OrderItems}"  
       Margin="0 5"  
       RowIndicatorVisibility="Collapsed"  
       ScrollViewer.HorizontalScrollBarVisibility="Auto"  
       ScrollViewer.VerticalScrollBarVisibility="Auto"  
       SelectionMode="Single"  
       SelectionUnit="FullRow"  
       ShowGroupPanel="False"  
       VerticalAlignment="Top"  
       >  
       <telerik:RadGridView.GroupHeaderTemplate>  
         <DataTemplate DataType="customers:CustomerOrderGrouRow">  
           <Grid>  
             <Grid.RowDefinitions>  
               <RowDefinition Height="Auto"/>  
             </Grid.RowDefinitions>  
             <Grid.ColumnDefinitions>  
               <ColumnDefinition Width="592"/>  
               <ColumnDefinition Width="Auto"/>  
             </Grid.ColumnDefinitions>  
             <TextBlock  
               Grid.Row="0"  
               Grid.Column="0"  
               Margin="10 0 0 0"  
               Text="{Binding Group.Key.OrderTypeName}"   
               />  
             <TextBlock  
               Grid.Row="0"  
               Grid.Column="1"  
               Margin="150 0 0 0"  
               Text="{Binding Group.Key.OrderCost}"   
               />  
           </Grid>  
         </DataTemplate>  
       </telerik:RadGridView.GroupHeaderTemplate>  
       <telerik:RadGridView.GroupDescriptors>  
         <telerik:GroupDescriptor Member="GroupItem"/>  
       </telerik:RadGridView.GroupDescriptors>  
       <telerik:RadGridView.Columns>  
         <!--OrderType-->  
         <telerik:GridViewColumn  
           GroupMemberPath="GroupItem"  
           IsSortable="True"  
           IsVisible="False"  
           MaxWidth="190"  
           MinWidth="80"  
           SortMemberPath="OrderType"  
           Width="130"  
           >  
         </telerik:GridViewColumn>  
         <!--FirstName-->  
         <telerik:GridViewColumn  
           Header="FirstName"  
           HeaderTextAlignment="Left"  
           IsSortable="True"  
           MaxWidth="220"  
           MinWidth="220"  
           SortMemberPath="FirstName"  
           Width="220"  
           >  
           <telerik:GridViewColumn.CellTemplate>  
             <DataTemplate  
               DataType="customers:CustomerOrderViewModel"  
               >  
               <TextBlock  
                 Margin="5"  
                 Text="{Binding FirstName}"  
                 TextAlignment="Left"  
                 />  
             </DataTemplate>  
           </telerik:GridViewColumn.CellTemplate>  
         </telerik:GridViewColumn>  
         <!--LastName-->  
         <telerik:GridViewColumn  
           Header="LastName"  
           HeaderTextAlignment="Left"  
           IsSortable="True"  
           MaxWidth="220"  
           MinWidth="220"  
           SortMemberPath="LastName"  
           Width="220"  
           >  
           <telerik:GridViewColumn.CellTemplate>  
             <DataTemplate  
               DataType="customers:CustomerOrderViewModel"  
               >  
               <TextBlock  
                 Margin="5"  
                 Text="{Binding LastName}"  
                 TextAlignment="Left"  
                 />  
             </DataTemplate>  
           </telerik:GridViewColumn.CellTemplate>  
         </telerik:GridViewColumn>  
         <!--Email-->  
         <telerik:GridViewColumn  
           Header="Email"  
           HeaderTextAlignment="Left"  
           IsSortable="True"  
           MaxWidth="220"  
           MinWidth="220"  
           SortMemberPath="Email"  
           Width="220"  
           >  
           <telerik:GridViewColumn.CellTemplate>  
             <DataTemplate  
               DataType="customers:CustomerOrderViewModel"  
               >  
               <TextBlock  
                 Margin="5"  
                 Text="{Binding Email}"  
                 TextAlignment="Left"  
                 />  
             </DataTemplate>  
           </telerik:GridViewColumn.CellTemplate>  
         </telerik:GridViewColumn>  
         <!--Order Cost-->  
         <telerik:GridViewDataColumn  
           Header="Order Cost"  
           HeaderTextAlignment="Left"  
           IsFilterable="False"  
           IsSortable="True"  
           MaxWidth="115"  
           MinWidth="115"  
           SortMemberPath="OrderCost"  
           Width="115"  
           >  
           <telerik:GridViewColumn.CellTemplate>  
             <DataTemplate  
               DataType="customers:CustomerOrderViewModel"  
               >  
               <TextBlock  
                 Margin="5"  
                 Text="{Binding OrderCost}"  
                 TextAlignment="Right"  
                 />  
             </DataTemplate>  
           </telerik:GridViewColumn.CellTemplate>  
         </telerik:GridViewDataColumn>  
       </telerik:RadGridView.Columns>  
     </telerik:RadGridView>  
   </Grid>  
 </Window>  
Finally in the codebehind file (MainWindow.xaml.cs) add the following code
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            var viewModel = new MainWindowViewModel();
            DataContext = viewModel;
        }
    } 
After writing all above code output window looks below

Saturday, July 2, 2011

Silverlight 5 Beta has released

Silverlight is one of the best tools developed by Microsoft to develop Rich UI Applications.
Microsoft is adding more features release by release. Currently new available version is Silverlight5 beta. Let's see some of the awesome features in Silverlight5 beta

1.Debugging feature for XAML Code.
2. Data templates maintained implicitly for UI Reusing easily.

To read more and download silverlight5 beta follow the below link

http://www.silverlight.net/getstarted/silverlight-5-beta/

Wednesday, August 4, 2010

Innovation - Good one

NON STOP TRAIN BUT U CAN BOARD AND COME OUT OF IT

Saturday, June 12, 2010

C# (csharp) 2.0 Improvements/Features

With the release of Visual Studio 2005, the C# language has been updated to version 2.0, which supports the following new features:

Generics
Generic types are added to the language to enable programmers to achieve a high level of code reuse and enhanced performance for collection classes. Generic types can differ only by arity. Parameters can also be forced to be specific types. For more information, see Generic Type Parameters.

Iterators
Iterators make it easier to dictate how a foreach loop will iterate over a collection's contents.

Partial Classes
Partial type definitions allow a single type, such as a class, to be split into multiple files. The Visual Studio designer uses this feature to separate its generated code from user code.

Nullable Types
Nullable types allow a variable to contain a value that is undefined. Nullable types are useful when working with databases and other data structures that may contain elements that contain no specific values.

Anonymous Methods
It is now possible to pass a block of code as a parameter. Anywhere a delegate is expected, a code block can be used instead: there is no need to define a new method.

Namespace alias qualifier
The namespace alias qualifier (::) provides more control over accessing namespace members. The global :: alias allows access the root namespace that may be hidden by an entity in your code.

Static Classes
Static classes are a safe and convenient way of declaring a class containing static methods that cannot be instantiated. In C# version 1.2 you would have defined the class constructor as private to prevent the class being instantiated.

External Assembly Alias
Reference different versions of the same component contained in the same assembly with this expanded use of the extern keyword.

Property Accessor Accessibility
It is now possible to define different levels of accessibility for the get and set accessors on properties.

Covariance and Contravariance in Delegates
The method passed to a delegate may now have greater flexibility in its return type and parameters.

How to: Declare, Instantiate, and Use a Delegate
Method group conversion provides a simplified syntax for declaring delegates.

Fixed Size Buffers
In an unsafe code block, it is now possible to declare fixed-size structures with embedded arrays.

Friend Assemblies
Assemblies can provide access to non-public types to other assemblies.

Inline warning control
The #pragma warning directive may be used to disable and enable certain compiler warnings.

volatile
The volatile keyword can now be applied to IntPtr and UIntPtr.

The C# compiler introduces the following additions and changes for this release:

/errorreport option
Can be used to report internal compiler errors to Microsoft over the Internet.

/incremental option
Has been removed.

/keycontainer and /keyfile options
Support specifying cryptographic keys.

/langversion option
Can be used to specify compatibility with a specific version of the language.

/linkresource option
Contains additional options.

/moduleassemblyname option
Allows you to build a .netmodule file and access non-public types in an existing assembly.

/pdb option
Specifies the name and location of the .pdb file.

/platform option
Enables you to target Itanium Family (IPF) and x64 architectures.

#pragma warning
Used to disable and enable individual warnings in code.

For More information visit below link

Ajax Enhancements/Improvements in ASP.NET 4.0


Ajax is an acronym for Asynchronous JavaScript and XML. It is a combination of different technologies, used for building rich and responsive user interfaces. The benefits of using Ajax in your applications include:
  • Faster page renderings and support for partial page updates
  • Rich and, responsive user interfaces
  • Reduced consumption of server resources

AJAX 4.0 provides some of the following features -
  1. Support for Live data binding
  2. Support for Client-side template rendering
  3. Support for declarative instantiation of client components
  4. Support for using the Observer pattern on JavaScript objects and arrays
  5. Support for invoking ADO.NET Data Services and Data Contexts
  6. Support for the DataView control

For More information visit below link

Friday, June 4, 2010

Chess Training in Kerala by FIDE Rated Player

People who are interested to get trained in chess you could contact the below address

Contact person name :BinjuOmmen Thottathil (FIDE Rated Player, Kerala state runner up)

Address:

Thirumoolapuram Village

Thiruvalla

Kerala.

phone:9447719077

Topics covered in Training

Basics,

Advanced,

Opening theories,

Tactics and Puzzle solving

Wednesday, May 19, 2010

CSharp 4.0 New Features

Dynamic binding

Dynamic binding allows you to write method, operator and indexer calls, property and field accesses, and even object invocations which bypass the C# static type checking and instead gets resolved at runtime.

To practice example follow the link

http://www.dotnetspark.com/kb/1206-overview-dynamic-type-c-sharp-40.aspx

Named and optional arguments

Parameters in C# can now be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted. Furthermore, any argument can be passed by parameter name instead of position.

To Read more info visit below link

http://cherupally.blogspot.com/2009/11/c-40-new-features-named-and-optional.html

COM specific interop features

Dynamic binding as well as named and optional arguments help making programming against COM less painful than today. On top of that, however, we are adding a number of other features that further improve the interop experience specifically with COM.

Variance

It used to be that an IEnumerable string wasn’t an IEnumerable object. Now it is – C# embraces type safe “co-and contravariance,” and common BCL types are updated to take advantage of that.

Refer below link for code sample explanation

http://andersnoras.com/post/100795246/c-4-0-covariance-and-contra-variance

Followers

Contributors