Pixytech

Category: Silverlight

  • 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;
            }
        }
  • RIA WCF Configuration (Finally Resolved):

    Finally after 3 days and nights i was able to find the solution for hosting RIA services on shared hosting environment and without changing anything on IIS. Yes it is possible…

    Why : RIA framework dynamically creates WCF service (Domain services) and add endpoints to the service.It first check if endpoint does’nt exist then create it,and it checks for 3 endpoints (http,soap and binary).After creating end points it adds authentication schema to end points.It picks IIS authentication schema’s and tries to apply on end points and failed to apply.

    If we could create desired end points in web.config RIA framework will not create or do anything with endpoints and it works succesfully ..

    You just need to follow the simple steps mentioned below :

    1. Add following code to you web.config to solve issue “This collection already contains an address with scheme http..”

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
      <baseAddressPrefixFilters>
        <add prefix="http://www.yoursite.com"/>
      </baseAddressPrefixFilters>
    </serviceHostingEnvironment>

    Note: Your service can be only accessed by url mentioned in above settings. As configured above you can’t access your service via http://yoursite.com.
    You could also use factory code to host WCF (see below) to resolve this error however alone with that you need to create svc files for each domain service.

    2.Add AspNetCompatibilityRequirementsMode attribute to your RIA Domain services classes
    Eg .Attrubtes added to AuthenticationService class under services folder

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AuthenticationService : AuthenticationBase<User> { }

    RIA framework dynamically apply these attributes after creating end points.Since we are now bypassing endpoint creation , we need to manually apply these attributes.

    3. For each RIA domain service add following to you configuration file.
    Eg. Is shown for AuthenticationService and UserRegistrationService
    Where SparkExams is my custom namespace.

    <services>
      <service name="SparkExams.Web.AuthenticationService"
      behaviorConfiguration="RIAServiceBehavior">
        <endpoint address="" binding="wsHttpBinding"
        contract="SparkExams.Web.AuthenticationService" />
        <endpoint address="/soap"
        binding="basicHttpBinding"
        contract="SparkExams.Web.AuthenticationService" />
        <endpoint address="/binary"
        binding="customBinding"
        bindingConfiguration="BinaryHttpBinding"
        contract="SparkExams.Web.AuthenticationService" />
      </service>
      <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" />
      </service>

    Please note that RIA adds 3 endpoints and if any of these endpoints are missing from web.config it will throw “IIS specified authentication schemes ‘Basic, Anonymous’…” error.
    Add following behaviours and bindings to your web.config

    <behaviors>
      <serviceBehaviors>
        <behavior name="RIAServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="BinaryHttpBinding">
          <binaryMessageEncoding />
          <httpTransport />
        </binding>
      </customBinding>
    </bindings>

    Test you wcf end points using WCF client test tool (Test client for Windows Communication Foundation services.) WcfTestClient.exe : Go to VS 2008 Console and type WcfTestClient.exe.

    Note that there is no need to host you service,or change IIS settings by ISP.
    Update : While working on SL project i have noticed that SL is not able to recieve faults/exceptions thrown by RIA domain service.Please follow article to fix the issue “Silverlight Faults in SL 3.0 with RIA Domain Services – Fix 2 – Must read

    Finally code and live demo application link are here..

    Demo Application link
    /rajnish/RiaTest/

     Custom service link
    /rajnish/RiaTest/DeployTest-Web-services-CustomService.svc

    Link to binay files for above links
    /rajnish/uploads/code/RiaTest/Binary.zip

    //Source code of application (Web.config has been changed in binary.zip)
    /rajnish/uploads/code/RiaTest/Source.zip

    If you are having any problem related to hosting Sl,copy binay.zip contents to your virtual directory on web server and modify web.config (bottom)
    add prefix=”/rajnish/

    If you have any problem with your code , then please download the binary.zip extract the contents and create virtual directory say RiaTest on your domain and copy the contents of Binary.zip (files like Default.aspx,DeployTestTestPage.aspx etc) to your web server.Change web.config “prefix section as mentioned above.Eg. on my webserver www.rajneeshnoonia.com i have created RiaTest virtual directory and copyied the contents of binary.zip into it.first step is to test your web service with URL like /rajnish/RiaTest/DeployTest-Web-services-CustomService.svc. if web service is ok you can launch your silverlight application.

    Note: the site will not work if you try to launch with /rajnish/… rather it will work if you try /rajnish/