ASPHostDirectory Cheap .NET 4 Hosting

Blog about .NET Hosting and all its latest technology

ASPHostDirectory.com .NET 4 Hosting :: Using Dynamic Objects in Silverlight 4

clock July 15, 2010 06:32 by author Darwin

This article gives brief explanation about Silverlight 4. If you’re looking for Silverlight 4 hosting, you can get the professional hosting at ASPHostDirectory. Only with $ 3.99/month to get SL 4 hosting. What are you waiting for?

One of the cool new features in Silverlight 4 is the ability to data bind to indexed properties. This means that even if you don’t know at design time what properties you data object has you can still data bind to them.

The syntax is very similar to a normal data binding, only in this case you need to use the [key] syntax instead. For example in example below the FirstName is a regular property while the LastName below is an indexed property.

<StackPanel Name="LayoutRoot"> 
    <StackPanel Orientation="Horizontal" Margin="1"> 
        <TextBlock Text="FirstName" Width="150"></TextBlock> 
        <TextBox Text="{Binding FirstName, Mode=TwoWay}" Width="500"></TextBox> 
    </StackPanel> 
    <StackPanel Orientation="Horizontal" Margin="1"> 
        <TextBlock Text="LastName" Width="150"></TextBlock> 
        <TextBox Text="{Binding [LastName], Mode=TwoWay}" Width="500"></TextBox> 
    </StackPanel>
</StackPanel>

Creating the class to data bind to is simple. All you need to do is add a property with the following syntax:

public object this[string key] 
    { get; set; }

In this example we are using a Peron class with a regular FirstName property and all others are dong using indexed properties. The complete class, including INotifyPropertyChanged looks like this:

public class Person : INotifyPropertyChanged

    public Person() 
   
        PropertyChanged = (s, e) => { };

        FirstName = "Maurice"; 
        this["LastName"] = "de Beijer";
        this["BabyName"] = "Kai"; 
    }

    private Dictionary<string, object> _data = new Dictionary<string, object>(); 
    public object this[string key] 
   
        get 
       
            if (!_data.ContainsKey(key)) 
                _data[key] = null;

            return _data[key]; 
       
        set 
       
            _data[key] = value; 
            PropertyChanged(this, new PropertyChangedEventArgs("")); 
       
    }

    public IEnumerable<string> Keys 
    {
        get 
        {
            return _data.Keys; 
        }
    }

    private string _firstName; 
    public string FirstName
   
        get
       
            return _firstName;
       
        set 
       
            _firstName = value; 
            PropertyChanged(this, new PropertyChangedEventArgs("FirstName")); 
       
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

While not having to know the objects structure at design time is nice but in the XAML above we still hard coded the data bindings so that doesn’t buy us much yet. So fully utilize this we need to dynamically generate the UI as well. Fortunately that is quite easy to do with the following code:

void MainPage_Loaded(object sender, RoutedEventArgs e)

    var person = new Person(); 
    DataContext = person; 
    foreach (var item in person.Keys) 
   
        var lbl = new TextBlock(); 
        lbl.Text = item; 
        lbl.Width = 150;

        var txt = new TextBox(); 
        var binding = new Binding("[" + item + "]"); 
        binding.Mode = BindingMode.TwoWay; 
        txt.SetBinding(TextBox.TextProperty, binding); 
        txt.Width = 500;

        var line = new StackPanel(); 
        line.Orientation = Orientation.Horizontal; 
        line.Children.Add(lbl); 
        line.Children.Add(txt); 
        line.Margin = new Thickness(1); 
        LayoutRoot.Children.Add(line); 
    }
}

And now you can see the result. Try it!
Happy Programming!

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!



ASPHostDirectory.com .NET 4 Hosting :: Virtualization in Silverlight 4 RC

clock July 10, 2010 10:20 by author Darwin

Introduction

There are several container controls in Silverlight . One of them is panel. Container control like for example StackPanel host another controls. Data presentation controls like ListBox inherits from ItemsControl. ItemsControl contains set of items to display and has ItemsSource property.ItemsControl is responsible for creating visuals for each item and placing them in a panel.


Main panel that holds items in ItemsControl is ItemsHost property. If we set this panel to be StackPanel for large datasets, ItemsContainerGenerator will generate containers that are off visible screen. Our ListBox will instantiate containers that aren't visible witch can take time and consume memory depending how large is dataset. Scrolling will also be much slower because we constantly computes the size and position of all of the containers.


Best solution for this problem is using UI virtualization. UI virtualization means that generation of items is deferred until we scroll items into visible zone. How it works? When we enable virtualization ItemHost property of ItemsControl is set to be VirtualizingStackPanel.


VirtualizingStackPanel calculates number of visible items and helps to create UI elements only for visible items. Scrolling on large datasets now will be much faster.


Another technique that can improve performance when working with large datasets is called Data virtualization. What does it mean? It means that we not load all data on client side rather only data that user can see at the moment. For example user in ListBox can see only 20 or 30 items. After that it must scroll. Here we can use technique called “deferred scrolling”. This technique you can see on Google Reader for example. We only loads 30 items from database and that user see. When user scroll down we load another 30 items from database. This technique can significantly improve performance of our application depend how large set of data we load on the client side.


Another example of Data virtualization is data pager control.We load 30 items in DataGrid control and when user click on link for next page then we load another 30 items.

2. UI virtualization

UI virtualization in Silverlight is accomplished by using VirtualizingStackPanel. As we have sad before VirtualizingStackPanel is that control that calculates the number of visible items to create UI elements only for visible items.

Virtualization in a StackPanel  occurs when the items control contained in the panel creates its own item containers. This happens when we use data binding. In case where item containers are created and added to the items control, a VirtualizingStackPanel offers no  advantage over a regular StackPanel.


VirtualizingStackPanel has two virtualization modes : standard and recycling. When we set standard mode containers are generated when items entering visible area. On the other hand when we set virtualization mode to be recycling we reuse containers that we have created before instead of generating new ones. Performance benefits of enabling recycling on VirtualizingStackPanel are significant especially for scrolling.

3. Data virtualization

Because off lack deferred scrolling on ScrollViewer it is not easy to implement “deferred scrolling”  in Silverlight 4 RC. In WPF we have this possibility to set deferred scrolling to true so we can make application that loads data when user releases scroll bar thumb.


But Silverlight has support for Data Virtualization using DataPager control and PagedCollectionView class. If we have DataGrid for example and we need to load large dataset with 500000 items in DataGrid maybe is better solution to implement paging on DataGrid using DataPager control.


We can use  a PagedCollectionView to provide grouping, sorting, filtering, and paging functionality for any collection that implements the IEnumerable interface. We just wrap IEnumerable collection with PageCollectionView and we have all this functionality. For example :

List<string> list = new List<string>();
//just provide to PagedCollectionView any IEnumerable datasource
PagedCollectionView p = new PagedCollectionView(list);
dataPager.Source = p;

PagedCollectionView has collection of GroupDescriptiors and SortDescriptiors that describes how items are group or sorted in view. It also contains methods for navigation between pages.

Code for grouping and sorting is simple. We just need to add new GroupDescription where we specify witch property in model will be used for grouping. For sorting code is similar. We just need to add new SortDescription and specify witch property will be used for sorting and in witch direction.

p.GroupDescriptions.Add(new PropertyGroupDescription("CustomerName"));
p.SortDescriptions.Add(new SortDescription("CustomerName",ListSortDirection.Ascending));

For filtering you need to define predicate that point to the method that will be used for filtering data.

p.Filter= new Predicate<object>(ExampleMethod);

4. Summary

As we have seen Silverlight 4 RC has very good support for UI virtualization. Using this technique we can improve performance of our Silverlight applications significantly.This give us tools to build high performance large business applications.

On the other hand Silverlight 4 RC does not support DeferredScrolling on ScrollViewer like WPF does. That makes difficult to implement “deferred scrolling” solutions in Silverlight. But probobly in later version of Silverlight this feature will be added because Silverlight and WPF eventually probably will become same platform. Silverlight also have very good support for paging through PagedCollectionView  that give us lot of functionality in simple way.

If you want to get professional Silverlight 4 RC hosting with low price, click here.

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory.com .NET 4 Hosting :: Build a Simple Application with .Net RIA Services (Silverlight 3)

clock June 19, 2010 07:39 by author Darwin

This article describe Build a Simple Application with .Net RIA Services in Silverlight 3. If you’re looking for more information about Silverlight, you can visit ASPHostDirectory. We always ready to host your site. You can start from only $ 3.99/month to get this hosting. So, what are you waiting for?

Use a DomainDataSource to easily connect the data

Remove the code that retrieves the data from the server. Open Views\HomePage.xaml and comment out all the code in the Page_Loaded method.

Instead of loading the data manually, add a DomainDataSource control to the page. To do this, add a reference to System.Windows.Ria.Controls.dll, and add the Xml namespace that relates to its contents:

<navigation:Page x:Class="BankApp.HomePage"

  ...
  xmlns:ria="clr-namespace:System.Windows.Controls;
    assembly=System.Windows.Ria.Controls"

  Loaded="Page_Loaded"

  Title="HomePage Page">

  ...

</navigation:Page>

Add the DomainDataSource to the page

<navigation:Page x:Class="BankApp.HomePage"
  ...

  <Grid x:Name="LayoutRoot" Background="White">

    <ria:DomainDataSource x:Name="customersDataSource"

                          LoadMethodName="GetCustomers"

                          AutoLoad="True"

                          LoadSize="5">

    </ria:DomainDataSource>

   ...

  </Grid>

</navigation:Page>

Reminder: After creating the DomainService in the server side, Visual Studio has generated a client side DomainContext that does all the magic of connecting to the server for us.

Assign the DomainContext to the DomainDataSource so it can use it to pull data from the server. To do that, add a local xml namespace:

<navigation:Page x:Class="BankApp.HomePage"

   ...

 
   xmlns:local="clr-namespace:BankApp.Web"

   Title="HomePage Page">
   ...

 
</navigation:Page>

And do the assignment:

<ria:DomainDataSource x:Name="customersDataSource"

                      LoadMethodName="LoadCustomers"

                      AutoLoad="True"

                      LoadSize="5">

  <ria:DomainDataSource.DomainContext>

    <local:BankDomainContext />

  </ria:DomainDataSource.DomainContext>

</ria:DomainDataSource>


The last thing we need to do is to bind the DataGrid to the DomainDataSource.

<data:DataGrid MinHeight="200"

              x:Name="dataGrid"

              ItemsSource="{Binding Data, ElementName=customersDataSource}">

</data:DataGrid>

Run the application, and see how the data is being loaded in chunks according to the LoadSize property of the DomainDataSource.

Add a DataPager Control to enable paging through the data. To do that, add a reference to System.Windows.Controls.Data.DataForm.dll the following xml namespace:

xmlns:dataControls=
    "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm”

Add the DataPager control and bind it to the DomainDataSource:

<data:DataGrid MinHeight="200" ...>

</data:DataGrid>

<dataControls:DataPager PageSize="3"

              Source="{Binding Data, ElementName=customersDataSource}" />

Data Grouping

Add Grouping support to the DataGrid. Add the following xml namespace:

xmlns:riaData="clr-namespace:System.Windows.Data;assembly=System.Windows.Ria.Controls"

Then, add a group descriptor to group the results by the property City.

<ria:DomainDataSource ...>
  <ria:DomainDataSource.GroupDescriptors>
    <riaData:GroupDescriptor PropertyPath="City" />
  </ria:DomainDataSource.GroupDescriptors>
</ria:DomainDataSource>

Data Sorting

To add sorting support, add a SortDescriptor:

<ria:DomainDataSource ...>

  <ria:DomainDataSource.SortDescriptors>

    <riaData:SortDescriptor PropertyPath="CustomerID"

                            Direction="Descending" />

  </ria:DomainDataSource.SortDescriptors>

</ria:DomainDataSource>

Rich Data Filtering

Add a dynamic filtering support based on a selected value of a CheckBox. Add a Checkbox above the DataGrid.

<CheckBox x:Name="chkBusiness"

          Content="Business Customer ?" />

<data:DataGrid x:Name="dataGrid" ...> </data:DataGrid>

Add a FilterDescriptor that filters data according to the IsBusiness property of each item. Bind the FilterDescriptor  to the IsChecked property of the above checkbox.

<ria:DomainDataSource x:Name="customersDataSource" ... >

  ...

  <ria:DomainDataSource.FilterDescriptors>

    <riaData:FilterDescriptorCollection>

      <riaData:FilterDescriptor PropertyPath="IsBusiness"

                                Operator="IsEqualTo">

        <riaData:ControlParameter ControlName="chkBusiness"

                                  PropertyName="IsChecked"

                                  RefreshEventName="Click" />

      </riaData:FilterDescriptor>

    </riaData:FilterDescriptorCollection>

  </ria:DomainDataSource.FilterDescriptors>

</ria:DomainDataSource>

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory.com .NET 4 Hosting :: How to Command Control

clock June 15, 2010 07:17 by author Darwin

In this article we will take this proof of concept and demonstrate how through the use of commanding and binding we can virtually eliminate all code behind and implement to a strong MVVM architectural pattern. For more information about silverlight 4 hosting, visit http://www.asphostdirectory. At ASPHostDirectory, we guarantee you will get the best price at an affordable price. Only $ 3.99/month, you will get Silverlight 4 hosting.

Getting Started

We think few would argue with the value of a strong separation of concerns within the design of an application.  Over the last year the MVVM pattern has gained popularity in the Silverlight development community.  One of the challenges that developers faced in previous versions of the framework was the lack of commanding support in Silverlight.  Without commanding many developers had to write there own attached properties, or worse  yet, resort to event handling in their code behind, just to deal with responding to a button being clicked.  Today both the button and HyperlinkButton support commanding.

Model-View-ViewModel

Even though our sample application will only be a single page, we will still implement the MVVM pattern to eliminate any code in code behind of our MainPage.xaml.  MVVM requires that for every View we have a corresponding ModelView (MV) class.  Our View will set its DataContext equal to this class and bind all of the views data through public properties.

using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

using System.ComponentModel;

namespace VideoCaptureExample
{
    public class MainPageViewModel : INotifyPropertyChanged
    {
    . . . . .
    }
}

In our mainPage.xaml we will initialize our ViewModel class and set our LayoutRoot DataContext to this resource.  If our ViewModel required additional context or possibly aservices be injected into its constructor we would opts to use a ViewModel locator that has been stored as a ApplicationResource.

<UserControl x:Class="VideoCaptureExample.MainPage"
    . . . .
    d:DesignHeight="360" d:DesignWidth="610">
    <UserControl.Resources>
        <local:MainPageViewModel x:Key="MainViewModel"/>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White"         DataContext="{Binding Source={StaticResource MainViewModel}}">
    . . . . . .
    </Grid>
</UserControl>

SaveCommand

One of the great advantages to commanding is encapsulation.  When an application has a function like “Save” its very likely that more then one action can trigger this behavior.  In our example we intend to allow the save to be triggered from a button, right click context menu as well a something being dragged to a specific location on the screen.  Creating a command has two parts.  First we need to write a class that implements the ICommand interface and second expose it through our view model..  The following is the general format of such a class.  When we create commands in Silverlight we like to inject our ViewModel in the event we need to check the state of our view before executing the command.

using System;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows.Input;

namespace VideoCaptureExample
{
    public class SaveCommand : ICommand
    {
        private MainPageViewModel _viewModel;

        public SaveCommand(MainPageViewModel viewModel)
        {
            _viewModel = viewModel;
        }

        public event EventHandler CanExecuteChanged;
        public bool CanExecute(object parameter)
        {
            return (_viewModel.SelectedCapture != null) ? true : false;
        }

        public void Execute(object parameter)
        {
            Capture capture = parameter as Capture;
            if (capture != null)
            {
             . . . . .
            }
        }

        protected virtual void OnCanExecuteChanged(EventArgs e)
        {
            var canExecuteChanged = CanExecuteChanged;

            if (canExecuteChanged != null)
                canExecuteChanged(this, e);
        }

        public void RaiseCanExecuteChanged()
        {
            OnCanExecuteChanged(EventArgs.Empty);
        }
    }
}

In the above snippet there are three requirements when implementing the ICommand interface.  First we need to define a function called CanExecute.  This will be called to determine if a buttons enabled state is set to true or false.  What is great about CanExecute is that it eliminates custom business logic to determine if a command can be fired.  The second is an Execute method that is called when the user clicks a button referenced by the command.  All of our “Save” logic will be placed inside of this method.  A argument is passed to this method that allows data to be injected into the call. Setting CommandParameter on a Button will define what gets passed during the execute. The last requirement is the CanExecuteChanged event.  We can fire this event anytime we want buttons that are bound to this command to re-evaluate there enabled state.

To implement this command in our ViewModel, we need to expose the class as a property.

private SaveCommand _saveCommand;
public SaveCommand Save
{
    get
    {
        if (_saveCommand == null)
            _saveCommand = new SaveCommand(this);
        return _saveCommand;
    }
}

Once exposed, we can reference the SaveCommand through simple binding applied to the Button’s Command property and CommandParameter.  Now each time that a user clicks the “Save” button our command will be fired.

<Button x:Name="saveBtn" Content="Save"
    Width="70" Height="22" Margin="10,0,0,0"
    HorizontalAlignment="Right" VerticalAlignment="Center"
    Command="{Binding Save}"
    CommandParameter="{Binding ElementName=listImages, Path=SelectedItem}"/>


DelegateCommand

More often than not our command is not needed outside of the context of a single view.  If this is the case, we can delegate the implementation of the CanExecute and Execute to the ViewModel.  Lets say for example you have a command like “StartCapture” that is only appropriate for a single View.  In this scenario its a lot easier to have the business logic directly in the ViewModel than in a separate class. 

Using the same ICommand interface, we can create a reusable class that delegates both of these methods.  The following is the most popular approach.

using System;
using System.Windows.Input;

namespace VideoCaptureExample
{
    public class DelegateCommand : ICommand
    {
        private Predicate<object> _canExecute;
        private Action<object> _method;
        public event EventHandler CanExecuteChanged;

        public DelegateCommand(Action<object> method)
            : this(method, null)
        {
        }

        public DelegateCommand(Action<object> method, Predicate<object> canExecute)
        {
            _method = method;
            _canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            if (_canExecute == null)
            {
                return true;
            }

            return _canExecute(parameter);
        }

        public void Execute(object parameter)
        {
            _method.Invoke(parameter);
        }

        protected virtual void OnCanExecuteChanged(EventArgs e)
        {
            var canExecuteChanged = CanExecuteChanged;

            if (canExecuteChanged != null)
                canExecuteChanged(this, e);
        }

        public void RaiseCanExecuteChanged()
        {
            OnCanExecuteChanged(EventArgs.Empty);
        }
    }
}

To implement this DelegateCommand class we do the following in our ViewModel.  Notice how our constructor gets passed two delegates, one for  CanExecute and one for Execute.  Calling this command from XAML is identical to our SaveCommand class.

private DelegateCommand _captureCommand;
public DelegateCommand Capture
{
    get
    {
        if (_captureCommand == null)
            _captureCommand = new DelegateCommand(OnCapture, CaptureCanExecute);

        return _captureCommand;
    }
}
. . . .
private void OnCapture(object parameter)
{
    UIElement element = parameter as UIElement;
    if (this.CaptureSource != null)
    {
    . . . .
    }
}
. . . .
private bool CaptureCanExecute(object parameter)
{
    return (_isCapturingVideo) ? true : false;
}

Using Binding to Avoid Commanding

One of the things that we think a lot developers forget is that TwoWay binding can be a great way to avoid having to create a command or event handler to respond to a user click.  Commands are great, but if you don’t need them don’t use them. 

If we examine the code below, you will see a bunch of bindings.  First, our ListBox.ItemSource is bound to an ObservableCollection<Effect> of effects.  This allows us to add effects to the ListBox by simply updating our collection.  Second, our ListBox.IsEnabled is bound to a property in our ViewModel.  Notice the use of TargetNullValue and FallbackValue.  These new properties on the binding extension method allow us to override what gets used in the event the property we are binding to is NULL value.  In this example we have a ViewModel property that stores a reference to a capture that has been selected in the ListBox of captures.  If nothing is selected, the property is null.  Since a null is not a boolean, we use TargetNullValue and FallbackValue to ensure we have a true/false response.

<ListBox Height="50" Name="listEffects" Width="Auto"  HorizontalAlignment="Stretch"
     ItemsSource="{Binding Path=Effects}"
     IsEnabled="{Binding TargetNullValue=true, FallbackValue=false, Path=SelectedCapture}"
     ItemTemplate="{StaticResource EffectItemTemplate}"
     ItemsPanel="{StaticResource WrapItemPanel}"
     ScrollViewer.HorizontalScrollBarVisibility="Disabled"
     ScrollViewer.VerticalScrollBarVisibility="Auto" >
</ListBox>

Another place we use binding is in the DataTemplate of this list box.  Here we will bind both the Effect of the rectangle and its Fill.  Our Effect will get bound to the ShaderEffect property of this item being rendered , while the Fill will navigate back to the main DataContext and bind to a property called Brush located within our  MainPageViewModel.  This property might be a SolidBrush, VideoBrush or even an ImageBrush of an existing capture.

<DataTemplate x:Key="EffectItemTemplate">
    <Border BorderThickness="1" BorderBrush="Black" CornerRadius="2"
        HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,3,0">
        <Rectangle Width="48" Height="36" Stretch="Fill"
            Effect="{Binding ShaderEffect}"
            Fill="{Binding Source={StaticResource MainViewModel}, Path=Brush}" />
    </Border>
</DataTemplate>

So that ensures that our list of effects looks correct, but how exactly does our rectangle displaying our live webcam video with the correct ShaderEffect applied? 

Again we lean on Binding to avoid any procedural code.  using ElementName binding we bind the styled buttons Effect property to the SelectedItem of our ListBox of effects.  Now each time a user clicks on an item in our list of effects the rectangles will change immediately.

<Button Name="rectVideo"
    Style="{StaticResource RectangleButtonStyle}"
    Width="320" Height="240"
    Effect="{Binding ElementName=listEffects, Path=SelectedItem.ShaderEffect, Mode=TwoWay}"
    Command="{Binding Capture}"
    CommandParameter="{Binding ElementName=rectVideo}"/>

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET Hosting :: Deploying a RIA Services Solution

clock June 12, 2010 07:01 by author Darwin

This topic describes the steps you must perform to deploy your WCF RIA Services application to a Web server. if you’re looking for information about Silverlight 4, you can choose ASPHostDirectory as alternatives. You’ll get the best service at an affordable price. Only with @ 3.99/month, you can directly get the services you want. So, what are you waiting for? Try it!!

Confirm That the .NET Framework 4 is Installed on the Web Server

The .NET Framework 4 must be installed on the Web server for a RIA Services application to work.

Install RIA Services on the Web Server

The RIA Services assemblies must be available on the Web server. You can make them available on the Web server by either including them in the Bin folder of your project or installing them in the global assembly cache (GAC).

- Bin Development

When deploying your application, you can include the RIA Services assemblies in the Bin folder of your project. To do this, you must select each reference in Visual Studio that you want to include and set the Copy Local property to True. After setting this value to True, the assemblies are copied to the Bin folder the next time you build the solution. When the assemblies are copied to the Bin folder, they will be copied to the Web server when you publish the site.

- GAC Development

Instead of copying the RIA Services assemblies in the Bin folder of every project that uses them, you can install the assemblies in the GAC. Any assemblies in the GAC are available to every application on the server. This approach is easier to maintain because an assembly only needs to be updated in the GAC instead of every Bin folder.

To install the RIA Services assemblies in the GAC on a Web server, run the following command.

msiexec /i RiaServices.msi SERVER=TRUE

Check Configuration Value

The Web.config files on the Web server must contain several values to enable RIA Services. By default, all of these values are set in the Web.config file when you create a RIA Services solution in Visual Studio. If you deploy this Web.config file, with any necessary changes to move from your development environment to the production environment, your RIA Services solution is properly configured. However, if you must retain an existing Web.config file, you will need to integrate the values for RIA Services. These values include the aspNetCompatibilityEnabled setting, the target framework, and domain service definitions. 

To set the aspNetCompatibilityEnabled property set to true, include the following element in Web.config:

<system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

</system.serviceModel>

To set the target framework to 4.0, include the following element:

<compilation targetFramework="4.0" />

To define the domain service module, specify it in the <httpModules> and <modules> elements:

<system.web>

  <httpModules>

    <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

  </httpModules>

</system.web>

<system.webServer>

  <modules runAllManagedModulesForAllRequests="true">

    <add name="DomainServiceModule" preCondition="managedHandler"

        type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

  </modules>

</system.webServer>

Ensure Only One Authentication Schema is Enabled

Only one authentication schema can be enabled when working with a RIA Services solution. Check the <authentication> element of your Web.config file and other configuration files in the hierarchy to ensure that more than one schema is not enabled.

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory ASP.NET Hosting :: How Can I Create Customized OOB Window?

clock June 3, 2010 07:03 by author Darwin

This topic contains information about key features and improvements in the Silverlight 4. This topic doesn’t provide comprehensive information about all new features and is subject to change. So, if you seek more information about Silverlight 4, you can choose ASPHostDirectory as alternatives. You’ll get the best service at an affordable price. Only with @ 3.99/month, you can directly get the services you want. So, what are you waiting for? Try it!!

Getting Started

If your development environment is ready then we can proceed towards creating a new Silverlight Application project. At the end of this part we will be able to run our first Silverlight application inside the browser.

1. Open your Visual Studio 2010 IDE
2. Select File > New Project or just press CTRL + SHIFT + N to open up the New Project dialog
3. Expand the “Visual C#” node and then go to sub node “Silverlight”
4. Select “Silverlight Application” in the right pane
5. Select proper location to store your application (let’s say, “D:\Sample Apps\”
6. Now enter a proper name for your project (call it as: “Silverlight4.OOB.ChromelessWindow.Demo”)
7. Select the .Net Framework version from the combo box at the top (I am using .Net Framework 4.0)
8. Click OK to continue
9. In the next dialog make sure that “Host the Silverlight application in a new Web site” option is selected
10. Choose “Silverlight 4” as the Silverlight Version and hit OK

Design Custom Chrome Window XAML

For our first step to give a look & feel of a customized window we have to create a “ControlBar” containing the Window Title, Maximize, Minimize & Close button. To do this, let us create an UserControl (for doing this, CustomControl is best rather than UserControl. But we are here using UserControl to give a simple approach for you to understand the main principle) inside the Silverlight project and name it as “ControlBar”.

Here is a simple design of the ControlBar which has a Title as TextBlock, Minimize, Maximize & Close buttons as Border wrapped with Canvas:

<Grid x:Name="grdControlBarRoot" Margin="0,0,0,0">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="15"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="100"/>
    </Grid.ColumnDefinitions>
    <Border Margin="0,0,0,0" Grid.ColumnSpan="3" Background="Black" Height="25"/>
    <TextBlock HorizontalAlignment="Left" Margin="0,0,5,0" VerticalAlignment="Center"
               Grid.Column="1" Text="{Binding Title, ElementName=userControl}"
               TextWrapping="Wrap" FontWeight="Normal" Foreground="White" x:Name="txbTitle"
               FontSize="12"/>
    <StackPanel x:Name="stpControlBarRoot" Grid.Column="2" Orientation="Horizontal"
                Margin="0,0,0,0" HorizontalAlignment="Right">
        <Canvas Width="30" x:Name="cnvMinimizeButton" Cursor="Hand" Background="#00000000"
                Visibility="Visible" Height="20" ToolTipService.ToolTip="Minimize">
            <Border Width="30" Height="20" Background="#FF939393" BorderBrush="#FF000000"
                    BorderThickness="1,1,0,1" CornerRadius="0,0,0,5">
                <Border BorderThickness="1.5,1.5,1.5,1.5" CornerRadius="0,0,0,5">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.514,0.623"
                                             StartPoint="0.514,0.191">
                            <GradientStop Color="#FF828282" Offset="0"/>
                            <GradientStop Color="#FF262626" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Rectangle Margin="6,9,6,3" Fill="#FFD6D5D5" Stroke="#FF000000"
                               StrokeThickness="0.5"/>
                </Border>
            </Border>
        </Canvas>
        <Canvas Width="30" x:Name="cnvMaximizeButton" Cursor="Hand" Background="#00000000"
                Visibility="Visible" Height="20" ToolTipService.ToolTip="Maximize">
            <Border Width="30" Height="20" Background="#FF939393" BorderBrush="#FF000000"
                    BorderThickness="1,1,0,1">
                <Border BorderThickness="1.5,1.5,1.5,1.5" CornerRadius="0,0,0,0" Width="29"
                        Height="18">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.514,0.623"
                                             StartPoint="0.514,0.191">
                            <GradientStop Color="#FF828282" Offset="0"/>
                            <GradientStop Color="#FF262626" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <Border Background="#FFD6D5D5" Margin="6,2,6,2" BorderBrush="#FF000000"
                            BorderThickness="0.5,0.5,0.5,0.5">
                        <Rectangle Stroke="#FF000000" Margin="2,2,2,2"
                                   StrokeThickness="0.5">
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF828282" Offset="0"/>
                                    <GradientStop Color="#FF262626" Offset="1"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                    </Border>
                </Border>
            </Border>
        </Canvas>
        <Canvas Width="40" x:Name="cnvCloseButton" Cursor="Hand" Background="#00000000"
                Opacity="1" Height="20" ToolTipService.ToolTip="Close">
            <Border Width="40" Height="20" Background="#FF939393" BorderBrush="#FF000000"
                    BorderThickness="1,1,1,1" CornerRadius="0,0,5,0">
                <Border BorderThickness="1,1,1,1" CornerRadius="0,0,5,0" Width="37"
                        Height="16" x:Name="border">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.514,0.623"
                                             StartPoint="0.514,0.191">
                            <GradientStop Color="#FF956161" Offset="0"/>
                            <GradientStop Color="#FF490E0E" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
                    <TextBlock Text="X" TextWrapping="Wrap" Foreground="#FFECECEC"
                               HorizontalAlignment="Center" VerticalAlignment="Center"
                               x:Name="textBlock"/>
                </Border>
            </Border>
        </Canvas>
    </StackPanel>
    <Rectangle Fill="#00FFFFFF" Margin="0,0,0,0" x:Name="rectTitleMask"
               Grid.ColumnSpan="2"/>
</Grid>

Implementing Custom Chrome Window Behavior

Now open the code behind file of the ControlBar.xaml and add a DependencyProperty named “Title” to it, which will be responsible to change the title of the Custom Window.

public string Title
{
    get { return (string)GetValue(TitleProperty); }
    set { SetValue(TitleProperty, value); }
}

public static readonly DependencyProperty TitleProperty =
    DependencyProperty.Register("Title", typeof(string), typeof(ControlBar), new PropertyMetadata(string.Empty));

Now, inside the constructor of the ControlBar class check whether the Application is running Out-of-Browser & has sufficient privileges to run. If so, then set the control visibility to visible and register the button events to fire the minimize, maximize & close events respectively. If the application is running inside the browser, just set the control’s visibility to collapsed and hence no need to register the events.
Here is the code snippet for you:

if (App.IsRunningOOBWithPermission)
{
    this.Visibility = Visibility.Visible;
    this.cnvMaximizeButton.MouseLeftButtonDown += cnvMaximizeButton_MouseLeftButtonDown;
    this.cnvMinimizeButton.MouseLeftButtonDown += cnvMinimizeButton_MouseLeftButtonDown;
    this.cnvCloseButton.MouseLeftButtonDown += cnvCloseButton_MouseLeftButtonDown;
    this.MouseLeftButtonDown += ControlBar_MouseLeftButtonDown;
}
else
{
    this.Visibility = Visibility.Collapsed;
}

Remember that “App.IsRunningOOBWithPermission” is a static property implemented inside the App class and it represents the boolean output of: “((App.Current.IsRunningOutOfBrowser) && (App.Current.HasElevatedPermissions))”.

There might be a question, what code to be write inside the event blocks? Don’t worry, you just have to do the operations as simplest as you can:

void ControlBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    App.Current.MainWindow.DragMove();
}

void cnvCloseButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    App.Current.MainWindow.Close();
}

void cnvMinimizeButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    App.Current.MainWindow.WindowState = WindowState.Minimized;
}

void cnvMaximizeButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    if (App.Current.MainWindow.WindowState == WindowState.Normal)
    {
        App.Current.MainWindow.WindowState = WindowState.Maximized;
    }
    else
    {
        App.Current.MainWindow.WindowState = WindowState.Normal;
    }

}

Configuring Out-of-Browser Settings

- Now add the “ControlBar” usercontrol inside your page and run your Silverlight application. You will find that the ControlBar is not present inside your browser window.

- Ok, then can we go further to install it outside the browser? Yes, but for this we have to do a little tricks. Go to the properties of the Silverlight project. From the Silverlight pane select the “Enable running application out of browser” which will make the “Out-of-Browser Settings…” button enabled. Click on it for more settings.

- From the Settings dialog window select “Show install menu” which will create a Menu Item inside the Silverlight context menu. Once you run your application and right click on the application you will see a “Install” menu item on it.

- Now, check the “Require elevated trust when running  outside the browser” as mentioned below and choose “Window Style” as “No Border”. This will make the default Chrome Window visibility to collapsed & if you run OOB, you will not see any Window border by default. Once you done with this settings, click ok to save the configurations. You can also change the “Window Title”, “Size” and other options available there.

Running OOB Application

Now build and run your application which will load inside the browser Window and you will not see any Control bar there as we wrote a code for collapsing the same if running inside the browser. Right click on the Silverlight application. This will show the Silverlight context menu having two menu items “Silverlight” & “Install” inside it. Click the second one to install the application to your local drive as OOB. Once installed it will automatically run the application out-of-browser window. Now you will see that it has our customized window rather than the default Window border. As we implemented, you can drag the Window from the Title Bar, minimize, maximize & even close the Window using our controls.

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!

 



ASPHostDirectory.com .NET 4 Hosting :: .NET RIA Services - Adding a DomainDataSource

clock May 29, 2010 08:09 by author Darwin

This article contains brief information about RIA Services. If you seek more information about RIA Services, you can choose ASPHostDirectory as alternatives. You’ll get the best service at an affordable price. Only with @ 6.99/month, you can directly get the services you want. So, what are you waiting for? Try it!!

Adding the DomainDataSource control


The DomainDataSource control can be found in the Systems.Web.Ria.Controls assembly and we have to declare the proper namespace in order to use it:

<navigation:Page x:Class="WebAdministrationTool.ManageUsers"

           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

           ...

           xmlns:ria="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls"

           ...

           Title="ManageUsers Page">

    <Grid x:Name="LayoutRoot">

        ...

        <ria:DomainDataSource x:Name="UsersDataSource"></ria:DomainDataSource>

        ...

    </Grid>

</navigation:Page>

The next step is to configure the DomainDataSource control to work with our DomainService class named UsersManager, which we have created in the previous article. The only thing we have to do is to set the DomainContext property:

<navigation:Page x:Class="WebAdministrationTool.ManageUsers"

           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

           ...

           xmlns:ria="clr-namespace:System.Windows.Controls;assembly=System.Windows.Ria.Controls"

           xmlns:local="clr-namespace:WebAdministrationTool"

           ...

           Title="ManageUsers Page">

<Grid x:Name="LayoutRoot">

    ...

    <ria:DomainDataSource x:Name="UsersDataSource" LoadMethodName="LoadAspnet_Users">

        <ria:DomainDataSource.DomainContext>

            <local:UsersManager />

        </ria:DomainDataSource.DomainContext>

    </ria:DomainDataSource>

    ...

</Grid>

</navigation:Page>

As the UsersManager class can be accessed through the generated code on the client we declare the namespace of our project in the XAML. We also specify the method that the DomainDataSource should use in order to load the data from the data base. Note that on the server our method is named GetAspnet_Users, but on the client it’s LoadAspnet_Users (see in the previous article how to use the DomainService on the client by using the managed code).

Adding a DataGrid control to the scene

Now as we have our DomainDataSource control prepared let’s add a Grid and bind them together:

<data:DataGrid x:Name="UsersGrid"

                       IsReadOnly="True"

                       AutoGenerateColumns="False"

                       HeadersVisibility="None"

                       GridLinesVisibility="None">

    <data:DataGrid.ItemsSource>

        <Binding ElementName="UsersDataSource" Path="Data" />

    </data:DataGrid.ItemsSource>

    <data:DataGrid.Columns>

        <data:DataGridTextColumn Binding="{Binding UserName}" />

    </data:DataGrid.Columns>

</data:DataGrid>

Using the Element-to-Element binding that came with Silverlight 3 we bind the ItemsSource of the DataGrid to the Data property of the DomainDataSource control.

Now let’s add a row details to our DataGrid, which will give more information about the selected user. First let’s take a look at the GetAspnet_Users of the UsersManager DomainService on the server:

public IQueryable<aspnet_Users> GetAspnet_Users()

{

    return this.Context.aspnet_Users;

}

It returns the content of the aspnet_Users table. In this table the only information we have is the username. The email, the comment and if the user is active can be found in the aspnet_Membership table and the information about the roles, that the user is in, is located in the aspnet_UsersInRoles table. These two tables are in relation with the aspnet_Users table and the associations between them are defined in the data model, so we can modify the get method in the following way:

public IQueryable<aspnet_Users> GetAspnet_Users()

{

    return this.Context.aspnet_Users.OrderBy( "it.UserName" )

                       .Include( "aspnet_Membership" )

                       .Include( "aspnet_UsersInRoles" );

}

In the previous article we configured the metadata for the aspnet_Users, so we can now use the following properties on the client:

internal sealed class aspnet_UsersMetadata

{

    ...

    [Include]

    public aspnet_Applications aspnet_Applications;

 

    [Include]

    public aspnet_Membership aspnet_Membership;

 

    [Include]

    public EntityCollection<aspnet_UsersInRoles> aspnet_UsersInRoles;

    ...

}


When the query is executed they are populated with the proper data. Now back on the client we have the following row details template for the DataGrid:


<data:DataGrid x:Name="UsersGrid"

               IsReadOnly="True"

               AutoGenerateColumns="False"

               HeadersVisibility="None"

               GridLinesVisibility="None">

        ...

    <data:DataGrid.RowDetailsTemplate>

        <DataTemplate>

            <Grid>

                <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="Auto" />

                    <ColumnDefinition />

                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>

                    <RowDefinition Height="Auto" />

                    <RowDefinition Height="Auto" />

                    <RowDefinition Height="Auto" />

                </Grid.RowDefinitions>

                <TextBlock x:Name="IsActiveLabel" Text="Is active:  " FontWeight="Bold" Grid.Column="0" Grid.Row="0" />

                <TextBlock x:Name="IsActiveBlock"
                           Text="{Binding aspnet_Membership.IsApproved,Converter={StaticResource BooleanConverter}}"
                           Grid.Column="1" Grid.Row="0" />

                <TextBlock x:Name="EmailLabel" Text="E-mail: " FontWeight="Bold"
                           Grid.Column="0" Grid.Row="1" />

                <TextBlock x:Name="EmailBlock" Text="{Binding aspnet_Membership.Email}"
                           Grid.Column="1" Grid.Row="1" />

                <TextBlock x:Name="DescriptionLabel" Text="Description: " FontWeight="Bold"
                           Grid.Column="0" Grid.Row="2" />

                <TextBlock x:Name="DescriptionBlock" Text="{Binding aspnet_Membership.Comment}"
                           Grid.Column="1" Grid.Row="2" />

            </Grid>

        </DataTemplate>

    </data:DataGrid.RowDetailsTemplate>

    ...

</data:DataGrid>

That’s it!

Paging the data

There is one last thing left to do – to add paging to the DomainDataSource. That can be easily accomplished by using the DataPager control (introduced with Silverlight 3). The control is located in the System.Windows.Controls.Data.DataForm assembly, so once again we have to declare a namespace in our XAML:

<navigation:Page x:Class="WebAdministrationTool.ManageUsers"

           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

            ...

           xmlns:validation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm"

            ...

           Title="ManageUsers Page">

    <Grid x:Name="LayoutRoot">

        ...

        <validation:DataPager x:Name="UsersPager"

                              PageSize="10"

                              Source="{Binding Data, ElementName=UsersDataSource}" />

    </Grid>

</navigation:Page>

Once bound to the Data property of the DomainDataSource control it handles the paging itself, we just have to set its page size. The most important thing to mention is that the DataPager control can page collections which implement the IPagedCollectionView interface. The Data property is such a collection.

Also here the LoadSize property of the DomainDataSource control can be found useful. It determines the count of the items to be loaded in the Data property of the control. For example we can set it to 10 and each time the page is changed only 10 items will be loaded. In the common case we set it to a number multiple to the page size. Another option is to set it to the count of the items, if it is known, so all items will be loaded and no other requests to the server will be made.

What is so SPECIAL on ASPHostDirectory.com Silverlight Hosting?

We know that finding a cheap, reliable web host is not a simple task so we’ve put all the information you need in one place to help you make your decision. At ASPHostDirectory, we pride ourselves in our commitment to our customers and want to make sure they have all the details they need before making that big decision.

We will work tirelessly to provide a refreshing and friendly level of customer service. We believe in creativity, innovation, and a competitive spirit in all that we do. We are sound, honest company who feels that business is more than just the bottom line. We consider every business opportunity a chance to engage and interact with our customers and our community. Neither our clients nor our employees are a commodity. They are part of our family.

The followings are the top 10 reasons you should trust your online business and hosting needs to us:

- FREE domain for Life - ASPHostDirectory gives you your own free domain name for life with our Professional Hosting Plan and 3 free domains with any of Reseller Hosting Plan! There’s no need to panic about renewing your domain as ASPHostDirectory will automatically do this for you to ensure you never lose the all important identity of your site
- 99,9% Uptime Guarantee - ASPHostDirectory promises it’s customers 99.9% network uptime! We are so concerned about uptime that we set up our own company to monitor people’s uptime for them called ASPHostDirectory Uptime
- 24/7-based Support - We never fall asleep and we run a service that is opening 24/7 a year. Even everyone is on holiday during Easter or Christmast/New Year, we are always behind our desk serving our customers
- Customer Tailored Support - if you compare our hosting plans to others you will see that we are offering a much better deal in every aspect; performance, disk quotas, bandwidth allocation, databases, security, control panel features, e-mail services, real-time stats, and service
- Money Back Guarantee - ASPHostDirectory offers a ‘no questions asked’ money back guarantee with all our plans for any cancellations made within the first 30 days of ordering. Our cancellation policy is very simple - if you cancel your account within 30 days of first signing up we will provide you with a full refund
- Experts in Silverlight Hosting
- Given the scale of our environment, we have recruited and developed some of the best talent in the hosting technology that you are using. Our team is strong because of the experience and talents of the individuals who make up ASPHostDirectory
- Daily Backup Service - We realise that your website is very important to your business and hence, we never ever forget to create a daily backup. Your database and website are backup every night into a permanent remote tape drive to ensure that they are always safe and secure. The backup is always ready and available anytime you need it
- Easy Site Administration - With our powerful control panel, you can always administer most of your site features easily without even needing to contact for our Support Team. Additionally, you can also install more than 100 FREE applications directly via our Control  Panel in 1 minute!

Happy Hosting!