European Silverlight 4 & Silverlight 5 Hosting BLOG

BLOG about Silverlight 5 Hosting and Its Techologies - Dedicated to European Windows Hosting Customer

European WCF 4.5 Hosting - Amsterdam :: Beyond Configuring Web Services in WCF 4.5

clock April 27, 2012 10:34 by author Scott

In previous post, you can see how easy it was to add a basic HTTP Web Service to a Web site in the beta of the .NET Framework 4.5 through code: Just add a shared/static method called Configure to your service and put some code in it to configure the ServiceConfiguration object passed to the method. In fact, because of the defaults that WCF 4.5 takes for a WCF service in a Web Site you don’t really need to add any code at all. In my example I did add some code to explicitly enable my service as a basic HTTP Web Service. I also chose to configure the service to return a contract and verbose error messages (both of which are turned off by default) to support testing.

But the power of WCF is in providing multiple ways of accessing the same code–as a basic Web Service or as a high performance TCP-based service. Adding TCP access requires a change in the project type: Testing a TCP-based service from Visual Studio is awkward (at best). Instead, you’ll want to create a WCF Service library where you service is hosted by WAS rather than IIS. While that makes testing your TCP access is simplified, the defaults don’t give you a service automatically and you’ll need to use a few more lines of code.


After creating your WCF Service library project add a new WCF Service to it, giving the service some meaningful name (I used “CustomerService”). Then, to demonstrate the power of configuring by code, go to your app.config file and delete the entire system.model element. You’re now ready to control your service from code.


These two lines of code make your service available as a Web Service and as a TCP-based service (which will have orders-of-magnitude better performance than the HTTP-based Web service):


PublicSharedSub Configure(sc AsServiceConfiguration)

sc.EnableProtocol(
New BasicHttpBinding
sc.EnableProtocol(
New NetTcpBinding)

While that (in theory) makes your service accessible, it doesn’t make the information about the service (the metadata) available. As a result, you won’t be able to either use Visual Studio’s WCF Test Client or be able add a service reference for your service to another project by using the Add Service Reference dialog’s Discover button. To enable the metadata you use the same code that I had in my previous post but with one extra line of code that specifies the address where the metadata is available. In that line you create a System.URI object specifying the address (the address must reference your computer name but the port and service name are up to you) and use it to set the HttpGetUrl property:


Dim behavior As New Description.ServiceMetadataBehavior

behavior.HttpGetEnabled =
True
behavior.HttpGetUrl = New System.Uri("http://localhost:1868/Customers")

sc.Description.Behaviors.Add(behavior)

You also need to add endpoints for HTTP and TCP access to your service. For that, you use the AddServiceEndpoint method on the ServiceConfiguration object passed to your Configure method. The first parameter to the AddServiceEndpoint is the type of the interface that your service implements (“ICustomers” in this example), the second parameter is the binding class for the endpoint, and the final parameter is the address itself (make sure that you use different addresses for each endpoint):


sc.AddServiceEndpoint(GetType(ICustomerService),

         New BasicHttpBinding(),
         "http://localhost:1868/Customers")
sc.AddServiceEndpoint(GetType(ICustomer),

         New NetTcpBinding(),  
         "net.tcp://localhost:1867/Customers")

There is an annoyance when you go to test your service: In a Service Library, in the absence of any entries in the config file, the test client can’t retrieve the information about the service. You’ll first get a dialog that the “WCF Service Host cannot find any service metadata”–just click the No button to continue. When the Test Client appears, it won’t display any services. You’ll need to go to the Test Client’s File menu and select Add Service to display the Add Service dialog box. In the box, enter the URL you used to set the HttpGetUrl property followed by “?wsdl” (e.g. “http://localhost:1868/Customers?wsdl”—and make sure you type the URL exactly the way it appears in your code). When you click the OK button, the Test Client will finally grab the service information and you’ll be able to test your service. The good news here is that, once you enter the URL with ?wsdl successfully, you won’t have to enter it again (you will still need to go through all the dialogs, though).

And there you go: With less than a dozen lines of code you’ve configured a service as both a basic HTTP service and TCP-based service. Adding additional access methods (e.g. named pipes, advanced web services, https) should just consist of enabling the protocol with the EnableProtocol method and adding a compatible endpoint.

 



European WCF Hosting - Amsterdam :: How to Solve - The type provided as the Service attribute could not be found

clock April 25, 2012 07:08 by author Scott

This had me stumped for a little while today. Whilst trying to host a WCF service in IIS we got this message when we tried to access the .svc file:

The type 'YourType, YourAssembly', provided as the Service attribute value in the ServiceHost directive could not be found.


At first the message seemed to be very specific about not being able to find the
type - almost as though it had found the assembly so I changed the YourAssembly to utter nonsense to see if the error changed. Alas no, so it was possible that the assembly couldn't be 'found', let alone the type.

Everything seemed to be in order as far as the assembly was concerned. He was in the bin folder and security was setup appropriately. The type, namespace and assembly were quadruple checked and
definitely correct. We even hooked up WinDbg and used the sxe ld YourAssembly command in the hope that we'd see the module attempt to load and fail. But nothing.

So I did what I always do in these situations and reverted to my ol' skool
Response.Write-ASP-classic-style debugging techniques. First step was to drop in an aspx page that used the Activator to create the type dynamically. Here's the ASPX page (no .aspx.cs required):

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Runtime.Remoting" %>

<%
ObjectHandle oh = Activator.CreateInstance("YourAssembly", "YourType");
Response.Write(oh.Unwrap().ToString() + " loaded OK");
%>

Just drop this page next to your .svc file and navigate to it in the browser. If it works and you can see the name of your type then you have a different problem to ours. I got an error that looked like this:


Could not load file or assembly 'SomeOtherAssembly' or one of its dependencies. The system cannot find the file specified.

Aha! So we could find the type specified in the Service attribute but we couldn't find some of its dependences. That's better - turns out I was missing an assembly that had to be GAC'd for this to work.



European Silverlight 5 Hosting - Amsterdam :: Client-side Collections Silverlight 5

clock April 24, 2012 06:33 by author Scott

With the release of Silverlight 5 just around the corner, I thought I would start a series on the new PivotViewer and how to get up and running with it. We will start the series off by exploring how to create a client side collection.

One of the most anticipated features of the new PivotViewer is the ability to create client-side collections. PivotViewer accomplishes this by utilizing the traditional ItemsSource property for data and a form of XAML data templates to define the trading card. It is interesting to note that the fundamental core of PivotViewer is still using the DeepZoom technology. If you are thinking that DeepZoom only handles images and not XAML, you would be correct. Under the hood, PivotViewer is rendering the data templates to images and then adding those images to DeepZoom. Remembering that little tidbit will help later down the road.


The Basics


First things first, let’s get a PivotViewer control into our application. One of the great changes in the PivotViewer is that instead of 4 libraries we are down to one. So to include the PivotViewer in your application, you simple need to add a reference to System.Windows.Controls.Pivot.


Now we can add a PivotViewer to our application like this:


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

    <pivot:PivotViewer x:Name="pViewer"/>
</Grid>


Doesn’t get much simpler than that, now does it?


Getting your Data


In order to focus in our demo, we are going to generate some dummy data on the client. Of course, you are most likely going to be pulling in more meaningful data (let’s hope anyway) and you can still do that in the traditional ways.


public class DemoItem : INotifyPropertyChanged

{

    public string ShortName { get; set; }

    private string _color;
    public string Color
    {
        get { return _color; }
        set
        {
            _color = value;
            NotifyProperty("Color");
        }
    }

    private int _value;
    public int Value

    {
        get { return _value; }
        set
        {
            _value = value;
            NotifyProperty("Value");
        }
    }

    private string _data1;
    public string Data1
    {
        get { return _data1; }
        set
        {
            _data1 = value;
            NotifyProperty("Data1");
        }
    }

    private DateTime _stamp;
    public DateTime Stamp
    {
        get { return _stamp; }
        set
        {
            _stamp = value;
            NotifyProperty("Stamp");
        }
    }

    public static ObservableCollection<DemoItem> BuildData()
    {
        var data = new ObservableCollection<DemoItem>();

        for (int i = 0; i < 100; i++)
        {
            var itm = new DemoItem()
             { ShortName = i.ToString("000") };

            var mod = i % 3;

            switch (mod)
            {
                case 0:
                    itm.Color = "Blue";
                    break;
                case 1:
                    itm.Color = "Red";
                    break;
                case 2:
                    itm.Color = "Green";
                    break;
            }

            itm.Data1 = i % 2 == 0 ? "Even" : "Odd";
            itm.Stamp = DateTime.Now.AddDays(-1*i);
            data.Add(itm);
        }

        return data;
    }

    #region INotifyPropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;

    public void NotifyProperty(string propName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this,
              new PropertyChangedEventArgs(propName));
    }

    #endregion

}

As you can see there isn’t a whole lot going on here. The BuildData() method knocks out some data that will let us see PivotViewer in action. I used a string for the color property so it would map to a PivotViewer property cleanly.


Now that we can generate our data, how do we get it into PivotViewer? It’s as simple as using the ItemsSource property (yep just like a normal Silverlight control).

pViewer.ItemsSource = DemoItem.BuildData();

Setting up your PivotProperties

In the original PivotViewer properties were defined as facets. In the new version we now have PivotProperties. There hasn’t been any changes to the number or types of properties. The four available types are :

1. PivotViewerStringProperty
2. PivotViewerNumericProperty
3. PivotViewerDateTimeProperty
4. PivotViewerLinkProperty

PivotViewer has a PivotProperties property (try saying that 3 times fast) that you can set via code or in XAML. For completeness sake, let’s take a look how each would look. Both of these examples yield the same result.

PivotViewer Properties in XAML:

<pivot:PivotViewer x:Name="pViewer">

    <pivot:PivotViewer.PivotProperties>
        <pivot:PivotViewerNumericProperty
            Id="Value"
            Options="None"
            Binding="{Binding Value}"/>
        <pivot:PivotViewerStringProperty
            Id="Data1"
            Options="CanFilter,CanSearchText"
            Binding="{Binding Data1}"/>
        <pivot:PivotViewerStringProperty
            Id="Color"
            Options="CanFilter,CanSearchText"
            Binding="{Binding Color}"/>
        <pivot:PivotViewerDateTimeProperty
            Id="Stamp"
            Options="CanFilter"
            Binding="{Binding Stamp}"/>
    </pivot:PivotViewer.PivotProperties>
</pivot:PivotViewer>


PivotViewer Properties in code behind:


pViewer.PivotProperties = new List<PivotViewerProperty>()

        {
            new PivotViewerNumericProperty()
                {
                    Binding = new Binding("Value"),
                    Id = "Value",
                    Options = PivotViewerPropertyOptions.None
                },
            new PivotViewerStringProperty()
                {
                    Binding = new Binding("Data1"),
                    Id = "Data1",
                    Options = PivotViewerPropertyOptions.CanFilter
                    | PivotViewerPropertyOptions.CanSearchText
                },
            new PivotViewerStringProperty()
                {
                    Binding = new Binding("Color"),
                    Id = "Color",
                    Options = PivotViewerPropertyOptions.CanFilter
                    | PivotViewerPropertyOptions.CanSearchText
                },
            new PivotViewerDateTimeProperty()
                {
                    Binding = new Binding("Stamp"),
                    Id = "Stamp",
                    Options = PivotViewerPropertyOptions.CanFilter
                }

        };

There are only a few options for a PivotProperty, so I thought it would be worth listing them. Here is a break down of each property and how it effects how the PivotProperty is used inside of PivotViewer

PivotProperty Options

None

No options are set

Private

If set, it will not display property in detail pane

CanFilter

Shows the property in the filter pane and the sort drop down box

CanSearchText

The search box will search for this property for matches

Wrapping Text

Will wrap the text within the detail pane


Trading Cards

Now we have our data and have mapped the data to the a collection of PivotProperties, what’s next? The last set it to define what the trading card is going to look like. For this post we are going to look at a basic solution which we will expand upon in the next post.


XAML data templates in PivotViewer take the shape of a PivotViewerItemTemplate. PivotViewer has a ItemTemplates property that is used to map one or more templates for your trading cards. For our case we are going to create a simple trading card that consists of a Border that is filled with the card’s Color property and put a ShortName property in the middle of the Border. The template will look something like this:

<pivot:PivotViewerItemTemplate x:Key="DemoTemplate">
    <Border Width="300" Height="300"
            Background="{Binding Color,
                    Converter={StaticResource colorConverter}}">
        <TextBlock Text="{Binding ShortName}" FontSize="20"
                   HorizontalAlignment="Center"
                   VerticalAlignment="Center" />
    </Border>
</pivot:PivotViewerItemTemplate>

You might notice that I added a value converter to the background. Since we are storing the color as a string, we need to map it to a SolidColorBrush. SL doesn’t expose all of the Color methods you find in .NET, so we have to be a bit clever in getting the color mapped. Here is the value converter that I am using:

public class TextToSolidColorConverter : IValueConverter

{


    public object Convert(object value,
                        Type targetType,
                        object parameter,
                        CultureInfo culture)
    {
        var xaml = "<SolidColorBrush " +
            "xmlns='http://schemas.microsoft.com/client/2007' " +
            "Color=\"" + value.ToString() + "\"/>";
        return XamlReader.Load(xaml);
    }

    public object ConvertBack(object value,
                        Type targetType,
                        object parameter,
                        CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

With our template added as a resource, we can set the template in code with the following:


pViewer.ItemTemplates = new PivotViewerItemTemplateCollection()
    {
        (PivotViewerItemTemplate) Resources["DemoTemplate"]
    };

And that is really all there is to it. If we run our solution, we should get something like this:



Press Release – HostForLIFE.eu Proudly Announces SQL 2012 Hosting for European Market

clock April 23, 2012 07:41 by author Scott

HostForLIFE.eu was established to cater to an under served market in the hosting industry; web hosting for customers who want excellent service. HostForLIFE.eu – a cheap, constant uptime, excellent customer service, quality, and also reliable hosting provider in advanced Windows and ASP.NET technology. We proudly announces the availability of the SQL 2012 hosting in our entire servers environment. HostForLife customer can choose SQL 2012 when creating a database from inside HostForLife hosting control panel.

The first new option is Windows SQL Server 2012, which is available to customers from today. With the public release just last week of Microsoft’s latest version of their premier database product, HostForLife has been quick to respond with updated their shared server configurations. SQL Server 2012 Web Edition is available for the same low monthly rental price as the previous SQL 2008, as well as Express Edition, which is a basic version of Microsoft’s SQL Database product, available for free.


“We’re proud to be at the cutting edge for new technologies. With these additions, customers have the option to explore these new products in the safe environment of their own shared server. Developers and IT Managers can research the potential impact of next-generation software without risking current infrastructure. With Microsoft’s announcement of the general availability of their new SQL server, we are proud to launch SQL 2012 hosting along with a suite of SQL 2012 management tools." Said John Curtis, VP Marketing and Business Development at HostForLIFE.eu.


John added, “It’s very important to our customers that we support their current deployments; we want to make sure that our customers have their good opportunity to test this new technology."


“HostForLIFE customers can now take advantage of SQL Server 2012’s advanced BI capabilities, We’re excited to see the benefits of this release add value to the energy management and manufacturing arena. Ensuring compatibility with Microsoft’s new SQL Server 2012 demonstrates how HostForLife and Microsoft remain committed together to providing leading edge technology for the benefit of our shared customers." Said CEO of HostForLIFE.eu, Anthony Johnson.


For more information about this new product, please visit
http://www.hostforlife.eu/SQL-2012-European-Hosting.aspx.

About us:


We are European Windows Hosting Provider which FOCUS in Windows Platform ONLY. We support Microsoft technology, such as the latest ASP.NET 4, ASP.NET MVC 3, SQL 2008/2008 R2, and much more.


Our number one goal is constant uptime. Our data center uses cutting edge technology, processes, and equipment. We have one of the best up time reputations in the industry.


Our second goal is providing excellent customer service. Our technical management structure is headed by professionals who have been in the industry since it's inception. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.

 



European Silverlight 5 Hosting - Amsterdam :: Silverlight 5 Pivot Viewer Control

clock April 16, 2012 09:24 by author Scott

In this article we will learn about creating a Pivot Viewer control in Silverlight .

Lets get started with a short description of what a PivotViewer Control is.


For this example I have used the Silverlight 5 PivotViewer, since most of us would have Silverlight 5 right now .


The Silverlight PivotViewer Control does not come by default with the Silverlight 4 toolkit. It has to be downloaded and installed separately .


With Silverlight 5 one would get the PivotViewer by default .


For Silverlight 4 it must be downloaded from the link shown below :


http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=17747


Once installed , the PivotViewer gets installed in the path as shown below :


C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\PivotViewer\Aug10


Hence forth I am using Silverlight 5 but similar steps needs to be followed for Silverlight 4.


Add a reference to the below DLL as shown below :




Let's start coding then . PivotViewer uses a special type of Collection called as Collection XML .


We need to understand Collection XML in order to effectively work with PivotViewer .


Collection XML (CXML) is the schema used to describe structured data to be displayed in the PivotViewer collection experience.


We make use of a class called CxmlCollectionSource to bind to the ItemSource of the PivotViewer


More Information on the CxmlCollectionSource can be found in the link below :


http://msdn.microsoft.com/en-us/library/system.windows.controls.pivot.cxmlcollectionsource(v=vs.96).aspx


Shown below is how the data is bound to the ItemSource property of the PivotViewer Control .




The final code is below :


            _cxml = new CxmlCollectionSource(new Uri("http://www.xpert360.net/PDC2010/PDC2010.cxml", UriKind.Absolute));

            pv1.PivotProperties = _cxml.ItemProperties.ToList();
            pv1.ItemTemplates = _cxml.ItemTemplates;
            pv1.ItemsSource = _cxml.Items;

Let's give it a run.




Cheers





European WCF 4.5 Hosting - Amsterdam :: One Line of Code to Configure WCF 4.5

clock April 10, 2012 11:47 by author Scott

The WCF 4.5 beta simplifies configuring WCF, provides better support for code-based configuration, and makes it easier to do code-based configuration in Web sites. Don’t get me wrong: I like the WCF configuration files but, I gather, I may be in a minority. Many developers prefer to configure their WCF services from code where possible. Unfortunately, one of the places where that isn’t possible is the most common place to host WCF services: in a Web application (well, I’m told it was possible but only in the sense that it’s possible to remove your own appendix).

WCF 4.5 (at least, in the beta) provides a simple solution: Add a static/shared method called Configure to your service class and fill it with the code required to configure your service. WCF will call that Configure method at the appropriate moment and pass the method an instance of the ServiceHost class. In your Configure method, you can work with that ServiceHost to configure your service.


What’s especially impressive is how simple it is. The default settings alone mean that if you add an svc file to your Web site then you have a Web Service. You can make that explicit, however, with a single line of code. This example makes the service containing this method available as a Web Service with no WCF-related tags required in the config file at all:


Public Shared Sub Configure(sc AsServiceConfiguration)

 sc.EnableProtocol(NewBasicHttpBinding())
End Sub

You can configure these services by instantiating behavior classes, configuring them, and adding them to the ServiceConfiguration’s Description property’s Behaviors collection. That’s a good thing because, while my previous example was all the code you need (in fact one more line than you needed), it’s probably not all the code you want, for two reasons.


Configuring the Service

First, with just that code you won’t be able to retrieve the WSDL contract for this service (what WCF refers to as service’s “metadata”) so you won’t be able to use Visual Studio’s WCF test client (you also won’t be able to use the Discover button in Visual Studio’s Add Service Reference dialog). For testing purposes, and until you can save to a separate file the WSDL contract that you can give to the developers building the clients/consumers for this service, you’ll want to configure your service to return a WSDL contract. To tell your service to make its metadata available you add code like the following to your Configure method. This code creates a ServiceMetadataBehavior object, sets its HttpGetEnabled property to True (that actually turns on the feature), and add the configured behavior to the Behaviors collection:

Dim behavior As New Description.ServiceMetadataBehavior
behavior.HttpGetEnabled = True
sc.Description.Behaviors.Add(behavior)


Second, by default, WCF services don’t return a lot of information in their exception messages. That’s a good thing: While that information is very useful in debugging, it probably isn’t something you want to share with the general public. However, in testing, you probably do want that those chattier error messages and you can enable the with this code in the Configure method:

Dim debugBehavior As New Description.ServiceDebugBehavior
debugBehavior.IncludeExceptionDetailInFaults = True
sc.Description.Behaviors.Add(debugBehavior)

But both of these changes highlight an issue with code-based configuration. In production, you probably don’t want your service freely giving up its contract to whoever asks for it. Instead you probably want to control access to your service’s contracts so that you have some idea who’s using your service and can contact those users when you’re making changes to your service. And you certainly don’t want to send out those verbose error messages from your production system. So, before moving your service to production you’re going to want to change the values used in this code.

The problem is that, with the code I’ve used here, there’s no simple way to inspect the assembly you’re deploying to production to determine if the settings are correct: the code is compiled and is unreadable. One of the nice features of the config files is that you could inspect them (and even change them) with Notepad. The right answer is probably to move settings that will change from one installation to another (e.g. test and production) into your AppSettings where you’ll still have visibility to them.

Please visit our site at
http://www.hostforlife.eu if you need Silverlight 5 WCF RIA hosting. Starts from only €2.45/month.

 



European WCF 4.5 Hosting - Amsterdam :: WCF 4.5 Features

clock March 22, 2012 07:14 by author Scott

This post discusses the new features in WCF 4.5. There have been significant improvements in WCF 4.5 on configuration.

Simplifying the generated configuration file in client

A client configuration file is generated when you add a service reference in Visual Studio 2010. The configuration files in earlier version of WCF contained the value of every binding property even if it is a default value. In WCF 4.5 Configuration files contain binding properties that are set to non-default value.


Example of configuration file generated by WCF 3.0



Example of same configuration file generated by WCF 4.5




Single WSDL File

In earlier version of WCF, WSDL document specifies dependencies via xsd:import attributes. WSDL file generated by WCF looks as below




Some clients may not consume the above WSDL file generated from WCF earlier version. In WCF 4.5 there is a single WSDL file and no external references to schema types.


When you browse the service metadata file in WCF4.5 then you will see the below options




If you want the single WSDL file then you can use the second link which ending with ?singlewsdl


Multiple Authentication Support on single end point in IIS

Hosting the WCF Service is bit tricky. You will get an error message when your service endpoint authentication is not matching the IIS’s authentication types.




ClientCredentialType
attribute is a new feature in WCF 4.5 which tells the service to inherit the authentication types from IIS host.

Now you can enable multiple authentication types in IIS




After enabling the authentication types in IIS then if you browse service’s WSDL file then you will see the below authentication types




WebSocket Support

Two new bindings have been added to support communication over a WebSocket transport.


NetHttpBinding and NetHttpsBinding


Streaming Improvements

Support for asynchronous streaming has been added to WCF. To enable asynchronous streaming, add the DispatcherSynchronizationBehavior endpoint behavior to the service host and set its AsynchronousSendEnabled property to true. You will get the scalability benefit when service sending streamed messages to multiple clients.

In earlier versions when you host WCF service on IIS, there were some around buffering the messages. When receiving a message for IIS hosted service which used to stream a message, asp.net would buffer entire message before sending it to WCF.

Now the buffering has been removed in .NET 4.5 and now IIS hosted WCF services can process the incoming stream before the entire message has been received.

More about the features can be read here

 



European Silverlight 5 Hosting - Amsterdam :: Debugging bindings in XAML Silverlight 5

clock March 19, 2012 08:03 by author Scott

One of the cool new tool features in Silverlight 5 is the XAML debugging features. It is limited to debugging bindings in XAML but that is an extremely useful feature.

I have created a demo showing the few steps needed to debug bindings in XAML. The demo consist of a TextBox containing a number a Button to refresh the number. The number is a random number.






The Text property of the TextBox binds to a property called “Number”. It is a Dependency Property defined in my code-behind. To make the binding work I have set the DataContext of the page to its self.




Whenever the Number property is updated it will automatically update the Text value on the TextBox.


As simple as it is I can spend hours looking for errors if I e.g. misspell the property that we use to bind to. Before Silverlight 5 I would get a hint in the Output window if I had a BindingExpression exception. In Silverlight 5 I can add a breakpoint to the binding directly in the XAML.




Debugging the XAML above I get an exception with a BindingExpression path error and enables me to easily identify the error.



European Silverlight 4 Hosting - Amsterdam :: How to Use AutoCompleteBox in Silverlight 4

clock March 14, 2012 07:44 by author Scott

In this article let us see how to use a AutoCompleteBox Control in a Silverlight application. As usual, open the visual studio and select the Silverlight project.

First let us drag a AutoCompleteBox to Stack Panel as shown below into
MainPage.xaml.

<sdk:AutoCompleteBox x:Name="CountriesNames" Width="200" />


Now we will add List to
AutoCompleteBox from MainPage.xaml.cs as shown below. In the below code, First i prepared list of type string and assigned a name "Countries" to it. Then i added strings( Countries names) to the list "Countries".

List<string> Countries = new List<string>();
             Countries.Add("India");
             Countries.Add("USA");
             Countries.Add("Japan");
             Countries.Add("UK");
             Countries.Add("Australia");
             Countries.Add("Switzerland");
             CountriesNames.ItemsSource = Countries;


At last i am binding this list "
Countries" to the "AutoCompleteBox" using its name "CountriesNames". Thats it!!! Just press F5 and see the result. The output of the above code looks like as

<image>


Note
: For the people who find it difficult to integrate the above code, I am pasting the complete code here.

MainPage.Xaml:

<UserControl x:Class="SilverlightTest1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <StackPanel Background="White">
        <StackPanel x:Name="LayoutRoot" Orientation="Horizontal">
            <TextBlock Text="CountriesList: " Margin="5" VerticalAlignment="Center" />
            <sdk:AutoCompleteBox x:Name="CountriesNames" Width="200" />
        </StackPanel>
     </StackPanel>

</UserControl>


MainPage.Xaml.cs:

public MainPage()
{
InitializeComponent();
List<string> Countries = new List<string>();
Countries.Add("India");
Countries.Add("USA");
Countries.Add("Japan");
Countries.Add("UK");
Countries.Add("Australia");
Countries.Add("Switzerland");
CountriesNames.ItemsSource = Countries;

}

 



European Silverlight 5 Hosting - Amsterdam :: Using the DatePicker control in Silverlight 5

clock March 5, 2012 07:27 by author Scott

This article introduces the DatePicker control present in the Silverlight Toolkit and shows how to use it in Silverlight applications.

The DatePicker control enables users to select dates using a Calendar like interface. It also includes a TextBox as part of its interface so that users can enter a date instead of selecting one from the Calendar.


The DatePicker control is not part of the Silverlight runtime, it is available in the Silverlight SDK. To use a control from the Silverlight SDK, you must add a reference to the assembly and include the appropriate XML namespace mapping in XAML.


For example,


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

Let us see how to use this control.


Create a new Silverlight 5 application named SilverlightDemo.


You can see the DatePicker control in the Toolbox.




Add the DatePicker control from the Toolbox into your application between the <Grid></Grid> tags.


The XAML markup will look as follows:


<UserControl x:Class="SilverlightDemo.MainPage"

xmlns
=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns
:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns
:d=http://schemas.microsoft.com/expression/blend/2008
xmlns
:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
mc
:Ignorable="d"
xmlns
:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
HorizontalAlignment
="Stretch" VerticalAlignment="Stretch">
<Grid x:Name="LayoutRoot" Background="White">

<sdk:DatePicker Height="23" HorizontalAlignment="Left" Margin="49,77,0,0" Name="datePicker1" VerticalAlignment="Top" Width="120" />

</Grid>

</UserControl>


Save, build, and execute the application. Click the calendar icon next to the Textbox in the DatePicker.




The default date format of the The DatePicker control is M/dd/yyyy. To change the format, you either use the SelectedDateFormat property which allows one of two values: Long or Short, or set the current culture of the thread to a new culture, which will also affect the date format. You can also change number of properties of this control.




Add a TextBox and a Button control to the page and configure the XAML markup as follows:


<UserControl x:Class="SilverlightDemo.MainPage"

xmlns
=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns
:x=http://schemas.microsoft.com/winfx/2006/xaml
xmlns
:d=http://schemas.microsoft.com/expression/blend/2008
xmlns
:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
mc
:Ignorable="d"
xmlns
:sdk=http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk
HorizontalAlignment
="Stretch" VerticalAlignment="Stretch">
<Grid x:Name="LayoutRoot" Background="White">

<TextBox x:Name="txtDate" Height="20" Margin="49,124,182,156" Width="99"/>

<sdk:DatePicker Height="23" HorizontalAlignment="Left" Margin="49,77,0,0" Name="datePicker1" VerticalAlignment="Top" Width="120" DisplayDateEnd="11/26/2012" SelectionBackground="#FFE83333" FontFamily="Georgia" FontSize="14" DisplayDateStart="{Binding Text, ElementName=txtDate, Mode=TwoWay}" />

<Button Height="25" Margin="40,167,169,108" Width="94" Content="OK"/>

</Grid>

</UserControl>


This markup sets the start date, end date, font style, selection background color, and binds the content of the text box to the DatePicker.

Some of the commonly used properties of the DatePicker control are:

Property

Description

BlackoutDates

Retrieves or assigns a collection of dates that are blacked out or unselectable

CalendarStyle

Retrieves or assigns the style that is used when rendering the calendar

DisplayDate

Retrieves or assigns the date to be displayed

DisplayDateEnd

Retrieves or assigns the beginning date in the calendar

DisplayDateStart

Retrieves or assigns the end date in the calendar

FirstDayOfWeek

Retrieves or assigns the day that is considered the beginning of the week

IsDropDownOpen

Retrieves or assigns a value that indicates whether the drop-down Calendar is open or closed

IsTodayHighlighted

Retrieves or assigns a value that indicates whether the current date is highlighted

SelectedDate

Retrieves or assigns the selected date

SelectedDateFormat

Retrieves or assigns the format that is used to display the selected date

SelectionBackground

Retrieves or assigns the background used for selected dates

 



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in