Pixytech

Category: C#

  • Prism 2.0

    Composite Application Guidance, affectionately known as Prism, version 2 was released in oct 2009.  Prism provides guidance and code that can help you build modular applications that can adapt to constant changing requirements. Prism guidance is a set of tools, samples, references and written guidance to help you more easily build modular applications.  Generally the “modular” application will feature several screens, flexible user interaction and role-based behavior.  Composite applications using these patterns are meant to be loosely coupled and contain independently evolving pieces that can work together. They are “built to last” and “built for change.” This means that the application’s expected lifetime is measured in years and that it will change in response to new, unforeseen requirements. This application may start small and over time evolve into a composite client—composite applications use loosely coupled, independently evolvable pieces that work together in the overall application. Applications that do not demand these features and characteristics may not benefit from the Composite Application Guidance.

     What’s new Prism 2.0?

    • Composite Support for Silverlight: Provides guidance on modularity, UI composition, commanding, and event aggregator in Silverlight. The Reference Implementation demonstrates how to use the Prism library with Silverlight.
    • Multi-targeting: Ability to share code between Silverlight and WPF. Provide guidance in the form of patterns, documentation, and tooling on how to share code between Silverlight and WPF. The tooling has its own msi that you can download.
    • Improved UI Composition: Added View Discovery to UI Composition. View Discovery: when a region is created, the region looks for all the ViewTypes associated with the region and automatically instantiates and loads the corresponding views. This is a simple approach to create new views.
    • Hands-on-Lab for Silverlight: Provide a Hands-on-Lab for Silverlight that walks you through how to create your first application using Prism.
    • New UI: Upgraded the UI with this release which includes new Silverlight and WPF animations.

     The Prism release adapts Model-View-ViewModel (MVVM) model (refers to this as the presentation model to match what some other pattern documentation in the greater technology world uses) in the reference implementation of the Stock Trader application.

    Prism 2 is an evolution from a July 2008 release (Prism 1) that was primarily for WPF applications.  The version v2 release brings updates and those concepts to Silverlight, including an implementation of commanding in Silverlight as well as demonstration of the use of input validation using these concepts.

    Prism consists of:

    • Reusable library components, for both WPF and Silverlight.
    • All source code, Unit tests, Automated acceptance tests.
    • Hands on labs (26) that guide you through all aspects of creating a composite application.
    • Quickstarts (9) that illustrate all components of prism.
    • A completely functional reference implementation that shows you how to build a composite application.
    • A lot of documentation and guidance:
      • How to create composite applications
      • How to use the Prism libraries
      • How to use Dependency Injection in your application (Unity)
      • How to create applications that target both WPF and Sliverlight.
      • Which design patterns were used to create prism
      • How to use separated presentation patterns (like Model – View – Viewmodel) to test your UI logic
      • And much, much more.
    • Api Reference documentation
    • A Visual Studio Plugin that helps you to target both WPF and Silverlight with a single codebase. 

    You should consider using prism:

    • If you want to create modular applications, in WPF and / or Silverlight so you can Develop, Test, Version and Deploy your modules independently of each other.
    • If you want to create an application that targets both WPF and Silverlight with a single codebase, or at least reuse a lot of code assets between WPF and Sliverlight.
    • If you want to minimize initial download size Silverlight applications. Prism allows you to just download the minimum of functionality you need to start your application. Other modules can be downloaded on a background thread or on demand.
    • If you are interested in using separated presentation patterns, because you want to create Unit Tests for your UI logic or if you want to make it easier to reskin your application.

    Links :

  • Silverlight – Implementing Clipboard support

    Silverlight 4 (currently in beta) adds support for Clipboard! – However no option to access html in clipboard.
    In Silverlight 3 we had copy/paste available in the Textbox, programmatic access could be done, some IE only solution exists via HTML DOM bridge (so not OOB) or cross-browser (involving Flash!). But now the game has changed as we now have an API for multi-platform Clipboard access.
    In this beta, the support is for (Unicode) text-only, and the Clipboard class has 3 static methods:
    • GetText()
    • SetText()
    • ContainsText()
    Clipboard access can only be done from a user initiated action (mouse, keyboard), and user is prompted to acknowledge the first time Clipboard is set or read (once per session).
    Silverlight 3 Clipboard Class


    Below is the class for Clipboard support in silverlight 3 or 4 with an additional method GetHtmlData() to return formated text from clipboard.
    Class Name : Clipboard.cs, Download Source Code.

    public static class Clipboard
    {
    public static void Copy(KeyEventArgs e, string s);
    private static string GetData(string type);
    public static string GetHtmlData();
    public static string GetTextData();
    public static void SetData(string data);
    public static bool IsEnabled;
    }

    Same tech. can be used in Silverlight 4 as this class provides methods like GetHtmlData() which can be used to get Html contents.This could be very helpfull in RichTextBox Editor,i.e if you could write parser for office html (mso) you may write code for copy/paste of contents from office applications to silverlight application.Example office excel cells will be treated as HTML table cells.Copying images from word documents will provide path to imagedata (VML) which can be then uploaded using OpenFileDialog calls..

    Regards
    Rajneesh Noonia

  • Implementing Silverlight Faults in SL 3.0 with RIA Domain Services – Fix 2

    Last month i have post article on how to host Silverlight (With RIA Domain services) project on shared domain. In that article (Link is Here ) some web.config settings are recommended to configure RIA end points. While working tonight i have noticed that Silverlight clients are not able to catch exceptions raised by DomainService ! and that’s because we have replaced the RIA default end point configurations via web.config settings. Silverlight version 3 enables support for the Windows Communication Foundation (WCF) SOAP fault programming model, which allows the service to communicate error conditions to the client. We need to perform following steps to enable error catch to Silverlight client. To send faults to a Silverlight client that are accessible to it, an WCF service must modify the way it sends its fault messages. The key change needed is for WCF to return fault messages with a HTTP 200 response code instead of the HTTP 500 response code. This change enables Silverlight to read the body of the message and also enables WCF clients of the same service to continue working using their normal fault-handling procedures.
    The modification on the server can be made by defining a WCF endpoint behavior for Silverlight faults. The following code sample shows how to do this.
    Create Project Paris.Silverlight and add class SilverlightFaultBehavior
    Copy the code as mentioned below (This has been taken from assembly System.Web.Ria 2.0.0.0) or follow link

    1.

    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Configuration;
    using System.ServiceModel.Description;
    using System.ServiceModel.Dispatcher;
    
    namespace Paris.Silverlight
    {
        public class SilverlightFaultBehavior : BehaviorExtensionElement, IEndpointBehavior
        {
            public SilverlightFaultBehavior()
            {
    
            }
            public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
            {
            }
    
            public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
            {
            }
    
            public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
            {
                SilverlightFaultMessageInspector inspector = new SilverlightFaultMessageInspector();
                endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
            }
    
            public void Validate(ServiceEndpoint endpoint)
            {
            }
    
            public override System.Type BehaviorType
            {
                get { return typeof(SilverlightFaultBehavior); }
            }
    
            protected override object CreateBehavior()
            {
                return new SilverlightFaultBehavior();
            }
        }
    
        public class SilverlightFaultMessageInspector : IDispatchMessageInspector
        {
            object IDispatchMessageInspector.AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
            {
                // Do nothing to the incoming message
                return null;
            }
    
            void IDispatchMessageInspector.BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
            {
                if (reply.IsFault)
                {
                    HttpResponseMessageProperty property = new HttpResponseMessageProperty();
                    property.StatusCode = System.Net.HttpStatusCode.OK; // 200
    
                    reply.Properties[HttpResponseMessageProperty.Name] = property;
                }
            }
    
        }
    }


    Compile the project and add reference of above assembly to your RIA web service project.

    Now we need to register the custom behaviorExtension element in web.config before doing that i would recommend to find full Qualified name of your assembly holding above class.

    Type code mentioned below to your start up aspx page

    string name = typeof(Paris.Silverlight.SilverlightFaultBehavior).AssemblyQualifiedName;

    copy the value of name , in my case thay are
    Paris.Silverlight.SilverlightFaultBehavior, SilverlightFaultBehavior, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    Note that you need to copy the same to web .config. Service may not work if you may put extra space or new line character in web .config.

    When registering a custom behaviorExtension element in your app.config to set up a custom endpoint behavior
    for a WCF service, WCF seems to require that the type attribute of the behaviorExtension matches *exactly* the assembly qualified name of the BehaviorExtensionElement class at a string level.

    2. Add RIASilverlightFaultBehavior to your web.config and also add behaviorConfiguration=”RIASilverlightFaultBehavior” to each endpoint of RIA service where address=”/binary”

    <service name="SparkExams.Web.UserRegistrationService" behaviorConfiguration="RIAServiceBehavior">
      <endpoint address="" binding="wsHttpBinding" contract="SparkExams.Web.UserRegistrationService" />
      <endpoint address="/soap" binding="basicHttpBinding" contract="SparkExams.Web.UserRegistrationService"/>
      <endpoint address="/binary" binding="customBinding"  bindingConfiguration="BinaryHttpBinding"
      contract="SparkExams.Web.UserRegistrationService"  behaviorConfiguration="RIASilverlightFaultBehavior"/>
    </service>

    Don’t forget to deploy SilverlightFaultBehavior assembly to your web server.
    Please also note that type attribute is space sensitive, use typeof(className).AssemblyQualifiedName to find type .
    Code and article has been tested against Vs 2008, and RIA 2.0 Beta.

    Click here for details on Fault Strategies in SL3

  • Adding User Management to your business application

    RIA “Business application” template adds login screen and logic to use Membership and role management.You just need to alter your web.cofig and create aspnet database.The configuration has already been cover in previous articles. In this article i will create Userdata metatdata class (for MembershipUser) and display all users in the system in DataGrid.User can also update some flags like IsApproved and IsLocked from this screen.User can also select single or multiple users from grid and click on delete to delete users from Membership. Users is not allowed to use IsLocked flag to lock account however he can use this checkbox to unlock the locked accounts.In this article we will learn how we can bind data grid to our custom entity,Update the data on web service when ever user changes anything in client side.Add custom validation to ensure that user is allowed to set IsLocked=false; and is not allowed to set IsLocked = true;

    1. To your web project add class UserData to Modles which will be used hold metadata for MembershipUser.

    public class UserData
    {  [Display(Order = 1, Name = "User Name")]
        [Key]
        public string UserName { get; set; }
        [ReadOnly(true)]
        [Display(Order = 2, Name = "Email")]
        public string Email { get; set; }
        [ReadOnly(true)]
        [Display(Order = 3, Name = "Created On")]
        public DateTime CreationDate { get; set; }
        [ReadOnly(true)]
        [Display(Order = 4, Name = "Last Login")]
        public DateTime LastLoginDate { get; set; }
        [ReadOnly(true)]
        [Display(Order = 5, Name = "Is Online")]
        public bool IsOnline { get; set; }
        [Display(Order = 6, Name = "Is Approved")]
        [Editable(true)]
        public bool IsApproved { get; set; }
        [Display(Order = 7, Name = "Is Locked")]
        [Editable(true)]
        [CustomValidation(typeof(Shared.Security.IsLockedOutValidator), "IsLockedOutValidValue")]
        public bool IsLockedOut { get; set; }
        [ReadOnly(true)]
        [Display(Order = 8, Name = "Last Lockout")]
        public DateTime LastLockoutDate
        {
            get;
            set;
        }
        [ReadOnly(true)]
        [Display(Order = 9, Name = "Last Activity")]
        public DateTime LastActivityDate { get; set; }
    }

     Note that properties IsApproved and IsLocked are editable and rest of all properties are readonly.Also custom validator class IsLockedOutValidator is used to validate that user is allowed to set IsLocked = false; and is not allowed to set IsLocked =true;

    2. Now again to you web project in shared folder add the class IsLockedOutValidator and name the file as IsLockedOutValidator.shared.cs.This will ensure that IsLockedOutValidator class is exposed to client for validations.Add following code to your class IsLockedOutValidator

    public class IsLockedOutValidator
    {
        public static ValidationResult IsLockedOutValidValue(bool value, ValidationContext context)
        {
            if (value == true)
            {
                return new ValidationResult("You can not lock user accounts ! Please use IsApproved to disable users.");
            }
            else
            {
                return ValidationResult.Success;
            }
        }
    }

     3. Now you need to add following methods to you Domainservice class

        public IEnumerable<Models.Security.UserData> GetUsers()
        {
            List<Models.Security.UserData> Users = new List<Models.Security.UserData>();
            foreach (MembershipUser u in Membership.GetAllUsers())
            {
                Users.Add(new Models.Security.UserData
                {
                    UserName = u.UserName,
                    CreationDate = u.CreationDate,
                    Email = u.Email,
                    IsApproved = u.IsApproved,
                    IsLockedOut = u.IsLockedOut,
                    IsOnline = u.IsOnline,
                    LastActivityDate = u.LastActivityDate,
                    LastLockoutDate = u.LastLockoutDate,
                    LastLoginDate = u.LastLoginDate,
                });
            }
            return Users;
        }
       public void DeleteUserData(UserData data)
        {
            Membership.DeleteUser(data.UserName);
        }
       public void UpdateUserData(UserData data)
        {
            //We need to only ensure that two properties are editable and values can be changed.
            MembershipUser u = Membership.GetUser(data.UserName);
            if (data.IsLockedOut == false && u.IsLockedOut)
                u.UnlockUser();
            u.IsApproved = data.IsApproved;
            Membership.UpdateUser(u);
        }

     Please note that if your entity name is UserData then method name used for addition,deletion,of update operation should be Update[EntityName],Delete[EntityName] i.e UpdateUserData,DeleteUserData .. etc.

    OK to this stage we have create our class to expose users registered under membership. We have exposed methods to update and delete users from membership. We have also added our custom validation shared class.

    Now let’s talk about silverlight client.

    To your xaml file add namespace “xmlns:dataGrid=”clr-namespace:System.Windows.Controls;assembly = System.Windows.Controls.Data” (you need to add appropriate ref. Before doing this)

    <dataGrid:DataGrid x:Name="grdUsers"
    CanUserReorderColumns="True"
    CanUserResizeColumns="True"
    CanUserSortColumns="True"
    AutoGenerateColumns="True"
    BorderBrush="Gray" />

    To code behind file add

    SecurityContext _context = new SecurityContext(); //Assuming this is your web service context

    In constructor of code behind

        this.Loaded += new RoutedEventHandler(Configurations_Loaded);
        grdUsers.RowEditEnded += new EventHandler<DataGridRowEditEndedEventArgs>(grdUsers_RowEditEnded);
       void grdUsers_RowEditEnded(object sender, DataGridRowEditEndedEventArgs e)
        {
            _context.SubmitChanges();
        }
       void Configurations_Loaded(object sender, RoutedEventArgs e)
        {
            grdUsers.ItemsSource = _context.UserDatas;
            _context.Load(_context.GetUsersQuery());
        }

    Add button “DeleteUser(s)” and on click event add following code

      private void DeleteUser(object sender, RoutedEventArgs e)
        {
            IEnumerable<UserData> list = grdUsers.SelectedItems.Cast<UserData>();
            List<UserData> alist = new List<UserData>();
            alist.AddRange(list);
            foreach (UserData u in alist)
            {
                _context.UserDatas.Remove(u);
            }
            _context.SubmitChanges();
        }

    Note that we are removing or changing _context.UserDatas and just using _context.SubmitChnages();This is call the appropriate UpdateUserData or DeleteUserData on web service.

  • Datapoint tooltip for silverlight chart toolkit

    Customized tooltip to Chart datapoints :

     

    Breaking Changes in Silverlight Toolkit October 2009
    Renamed Charting’s StylePalette to Palette (for clarity) AND changed its type to IEnumerable<ResourceDictionary> (from IEnumerable<Style>) for a significant flexibility boost. Performed related renamings (many internal/private): IStyleDispenser->IResourceDictionaryDispenser, StylePalette->ResourceDictionaryCollection, StyleDispensedEventArgs->ResourceDictionaryDispensedEventArgs, StyleDispenser->ResourceDictionaryDispenser, StyleEnumerator->ResourceDictionaryEnumerator.

    Most notably, this change makes it possible to associate MULTIPLE things with a palette entry and enables designers to easily and flexibly customize things like the LineSeries PolyLineStyle in the Palette. Additionally it enables the use of DynamicResource (currently only supported by the WPF platform) to let users customize their DataPointStyle without inadvertently losing the default/custom Palette colors. (Note: A very popular request!) Thanks to merged ResourceDictionaries, this also enables the addition of arbitrary resources at the Palette level (like Brushes) which can then be referenced by DataPoints, etc..

    So instead of using StylePalette we need to use Chat.Palette .The following code will add more business oriented tooltip to LineSeries DataPoint.
    Inside your chart tag in xaml file add following palette (for multiple line series styling). Note that palette uses template “CustomLineDataPointTemplate” which you need to define in Styles.xaml

    <chartingToolkit:Chart x:Name="OrdersChart" ..="" other="" properties="" here="" >
      <chartingToolkit:Chart.Palette>
        <datavis:ResourceDictionaryCollection>
          <ResourceDictionary >
            <!--Blue-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFB9D6F7"/>
                    <GradientStop Color="#FF284B70" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!--Red-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFFBB7B5"/>
                    <GradientStop Color="#FF702828" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!-- Light Green -->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFB8C0AC"/>
                    <GradientStop Color="#FF5F7143" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!-- Yellow -->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFFDE79C"/>
                    <GradientStop Color="#FFF6BC0C" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!-- Indigo -->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFA9A3BD"/>
                    <GradientStop Color="#FF382C6C" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!-- Magenta -->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFB1A1B1"/>
                    <GradientStop Color="#FF50224F" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!-- Dark Green -->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FF9DC2B3"/>
                    <GradientStop Color="#FF1D7554" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!--Gray Shade-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFB5B5B5"/>
                    <GradientStop Color="#FF4C4C4C" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!--Blue-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FF98C1DC"/>
                    <GradientStop Color="#FF0271AE" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!-- Brown -->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFC1C0AE"/>
                    <GradientStop Color="#FF706E41" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!--Cyan-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFADBDC0"/>
                    <GradientStop Color="#FF446A73" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!-- Special Blue -->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FF2F8CE2"/>
                    <GradientStop Color="#FF0C3E69" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!--Gray Shade 2-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFDCDCDC"/>
                    <GradientStop Color="#FF757575" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!--Gray Shade 3-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFF4F4F4"/>
                    <GradientStop Color="#FFB7B7B7" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
          <ResourceDictionary>
            <!--Gray Shade 4-->
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:LineDataPoint">
              <Setter Property="Background">
                <Setter.Value>
                  <RadialGradientBrush>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup>
                        <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="2.09" ScaleY="1.819"/>
                        <TranslateTransform X="-0.425" Y="-0.486"/>
                      </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FFF4F4F4"/>
                    <GradientStop Color="#FFA3A3A3" Offset="1"/>
                  </RadialGradientBrush>
                </Setter.Value>
              </Setter>
              <Setter Property="Template" Value="{StaticResource CustomLineDataPointTemplate}" />
            </Style>
          </ResourceDictionary>
        </datavis:ResourceDictionaryCollection>
      </chartingToolkit:Chart.Palette>
      Inside your Styles.xaml add following xaml
      <!-- Chart Data point style for tool tip-->
      <ControlTemplate x:Key="ToolTipTemplate">
        <Border BorderBrush="Gray" BorderThickness="0.5" CornerRadius="5" Background="White" >
          <Grid>
            <ContentPresenter
            Content="{TemplateBinding Content}"
            ContentTemplate="{TemplateBinding ContentTemplate}"
            Margin="{TemplateBinding Padding}"
            VerticalAlignment="Center"/>
          </Grid>
        </Border>
      </ControlTemplate>
      <ControlTemplate x:Key="CustomLineDataPointTemplate" TargetType="chartingToolkit:LineDataPoint">
        <Grid x:Name="Root" Opacity="0" Background="Transparent" >
          <ToolTipService.ToolTip>
            <ToolTip Margin="4" Template="{StaticResource ToolTipTemplate}" Content="{Binding DataPointTooltipText}" />
          </ToolTipService.ToolTip>
          <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="CommonStates">
              <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.1"/>
              </VisualStateGroup.Transitions>
              <VisualState x:Name="Normal"/>
              <VisualState x:Name="MouseOver">
                <Storyboard>
                  <ColorAnimationUsingKeyFrames BeginTime="00" Duration="00.0010000"
                  Storyboard.TargetName="MouseOverHighlight"
                  Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                    <SplineColorKeyFrame KeyTime="00" Value="#FFFFDF00"/>
                  </ColorAnimationUsingKeyFrames>
                  <DoubleAnimationUsingKeyFrames BeginTime="00" Duration="00.0010000"
                  Storyboard.TargetName="MouseOverHighlight"
                  Storyboard.TargetProperty="(UIElement.Opacity)">
                    <SplineDoubleKeyFrame KeyTime="00" Value="0.24"/>
                  </DoubleAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="SelectionStates">
              <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.1"/>
              </VisualStateGroup.Transitions>
              <VisualState x:Name="Unselected"/>
              <VisualState x:Name="Selected">
                <Storyboard>
                  <DoubleAnimationUsingKeyFrames BeginTime="00" Duration="00.0010000"
                  Storyboard.TargetName="SelectionHighlight"
                  Storyboard.TargetProperty="(UIElement.Opacity)">
                    <SplineDoubleKeyFrame KeyTime="00" Value="0.18"/>
                  </DoubleAnimationUsingKeyFrames>
                </Storyboard>
              </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="RevealStates">
              <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="0:0:0.5"/>
              </VisualStateGroup.Transitions>
              <VisualState x:Name="Shown">
                <Storyboard>
                  <DoubleAnimation Duration="0" Storyboard.TargetName="Root"
                  Storyboard.TargetProperty="Opacity" To="1"/>
                </Storyboard>
              </VisualState>
              <VisualState x:Name="Hidden">
                <Storyboard>
                  <DoubleAnimation Duration="0" Storyboard.TargetName="Root"
                  Storyboard.TargetProperty="Opacity" To="0"/>
                </Storyboard>
              </VisualState>
            </VisualStateGroup>
          </VisualStateManager.VisualStateGroups>
          <Ellipse Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}"/>
          <Ellipse RenderTransformOrigin="0.661,0.321">
            <Ellipse.Fill>
              <RadialGradientBrush GradientOrigin="0.681,0.308">
                <GradientStop Color="#00FFFFFF"/>
                <GradientStop Color="#FF3D3A3A" Offset="1"/>
              </RadialGradientBrush>
            </Ellipse.Fill>
          </Ellipse>
          <Ellipse x:Name="SelectionHighlight" Opacity="0" Fill="Red"/>
          <Ellipse x:Name="MouseOverHighlight" Opacity="0" Fill="White"/>
        </Grid>
      </ControlTemplate>

    The above code expects property DataPointTooltipText in the binding datasource.
    So to your chart series datasource class add following code…

        public DateTime LastRefreshTime = DateTime.Now;
        public object DataPointTooltipText
        {
            get
            {
                TextBlock tb = new TextBlock();
                tb.Inlines.Add(new Run { Text = "Title: ", FontWeight = FontWeights.Bold }); tb.Inlines.Add(new LineBreak());
                tb.Inlines.Add(new Run { Text = "Updated: " + LastRefreshTime.ToString() });
                tb.Inlines.Add(new LineBreak());
                //if (Growth >= 0)
                tb.Inlines.Add(new Run { Text = "Total Orders: " + _no_of_orders.ToString(), Foreground = new SolidColorBrush(Colors.Green) });
                tb.Inlines.Add(new LineBreak());
                //else
                tb.Inlines.Add(new Run { Text = "Time : " + _transtime.ToString(), Foreground = new SolidColorBrush(Colors.Red) });
                return tb;
            }
        }