The Acropolis Client Application Framework

The Acropolis Client Framework makes it easy to build flexible and powerful Windows Presentation Foundation (WPF) applications. Learn how to tap into the power of Acropolis and how it can help you deliver the next generation of client applications. In this session, we first describe the basic Acropolis" features and how you can use them to build rich WPF applications. We then move onto some of the more advanced features and show you how to leverage the frameworks flexibility to add rich navigation, theming, commanding, and supporting services to your applications.

Install Silverlight

How to Build A WPF Standard Application

This video shows how you can you build a WPF standard Application.

Silverlight Application and Programming Model

Application that are written for targeting Silverlight 2.0 platform using managed code uses Silverlight Application model. Application model refers to application packaging and the common functionality encapsulated by the Application class. The application model helps you to develop both simple applications and complex, extensible applications that can share resources across a network. Silverlight offers two different programming model for developing Silverlight applications.

  • The managed API for Silverlight
  • The JavaScript API for Silverlight

You can not use both these programming models at same time with in the single application. Managed API model provides more functionality as compare to JavaScript model because application using managed API model can also access lightweight .Net framework classes.

Silverlight Layout Container Panel: Grid

Grid is one of the Silverlight container layout panel that enable complex layout. By default grid contains one row and one column. RowDefinations and ColumDefinations collections also be used to define more rows and columns in Grid. RowDefination and ColumnDefination objects are used to define the size of each row and column inside Grid. In Silverlight Grid is designed to use for your application it is not design for displaying the data, it’s not like GridView in Visual Studio.

Grid.Column and Grid.Row properties are used to position objects in specific cells.

For scenarios that require application layout that is not possible using any of the predefined Panel elements, custom layout behaviors can be achieved by inheriting from Panel and overriding the default measure and arrange behavior by using the MeasureOverride and ArrangeOverride methods. For more information

Example

<UserControl x:Class="SilverlightApplication3.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="#DCDCDC" Width="400" Height="300" ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250" />
            <ColumnDefinition Width="150" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="2*" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1" Margin="10" FontWeight="Bold"  Foreground="Blue"  Text="Silverlight Grid Demo" HorizontalAlignment="Center" VerticalAlignment="Center" />
        <Grid x:Name="FormLayoutGrid" Grid.Row="1" Grid.Column="0" ShowGridLines="True">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" Grid.Column="0" Text="First Name" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" />
            <TextBox Grid.Row="0" Grid.Column="1" Margin="10" />
            <TextBlock Grid.Row="1" Grid.Column="0" Text="Last Name" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" />
            <TextBox Grid.Row="1" Grid.Column="1" Margin="10" />
            <TextBlock Grid.Row="2" Grid.Column="0" Text="Address" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" />
            <TextBox Grid.Row="2" Grid.Column="1" Margin="10" />
            <TextBlock Grid.Row="3" Grid.Column="0" Text="Email Address" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" />
            <TextBox Grid.Row="3" Grid.Column="1" Margin="10" />
        </Grid>
    </Grid>

</UserControl>

Silverlight Grid Demo

Silverlight Layout Container Panels : Stack Panel

Stack Panel is one of the Silverlight panel elements enable layout. Stack panel arranges objects in a list, list can be vertical or horizontal depending upon the direction. Orientation property determined the direction of list, default value of orientation property is vertical.

Example

<StackPanel Margin="20">
    <Rectangle Fill="Brown"  Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Blue" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Green" Width="50" Height="50" Margin="5" />
    <Rectangle Fill="Yellow"  Width="50" Height="50" Margin="5" />
</StackPanel>

Silverlight Layout Container Panels – Dock Panel

Silverlight Dock Panel is one of the Silverlight Panel that enables layout. DockPanel is used to arrange a set of objects around the edges of panel. Dock Panel’s Dock property enables you to specify the location of objects inside Dock Panel. If you set the LastChildFill property to true (the default value) and the last element is allowed to resize, the last element added to the panel will resize to fill the remaining space. If the last element is set to a specific size, the last element will be set to the specified size and positioned in the middle of the remaining space. The order in which elements are added to the DockPanel is important.

DockPanel

DockPanel Example

<Border BorderBrush="Black" BorderThickness="3" >
            <StackPanel x:Name="LayoutRoot" Background="White">
                <TextBlock Margin="5" Text="Dock Panel" />
                <Border BorderBrush="Black" BorderThickness="3" >
                    <controls:DockPanel LastChildFill="true" Height="265">
                        <Button  Content="Dock: Left" controls:DockPanel.Dock ="Left" />
                        <Button Content="Dock: Right" controls:DockPanel.Dock ="Right" />
                        <Button  Content="Dock: Top" controls:DockPanel.Dock ="Top" />
                        <Button  Content="Dock: Bottom" controls:DockPanel.Dock ="Bottom" />
                        <Button Content="Last Child" />
                    </controls:DockPanel>
                </Border>
            </StackPanel>
        </Border>

In Next we will discuss about Dock Panel Grid

Silverlight Layout Container Panels – Canvas Panel

When you start creating Silverlight based applications, one of first things you will need to choose how your Silverlight application layout. Silverlight provides five layout panels. The default panel is Grid panel.

Canvas Panel

Canvas is one of the Silverlight panel, that enables layout of your Silverlight applications. Control positing inside Canvas in controlled by specifying the X and Y coordinates of  controls. These coordinates are in pixel. Canvas.Left and Canvas.Top properties can also be use for specifying X and Y coordinates. Canvas objects can also be nested. Each child element must be UIElementChildren property is used for accessing Canvas child elements in code. Sometimes Canvas is used as a container for other objects in that Canvas does not have any visible property. A Canvas is not visible if any of the following conditions are true:

  • The Height property is equal to 0.
  • The Width property is equal to 0.
  • The Background property is equal to nullNothingnullptrunita null reference (Nothing in Visual Basic).
  • The Opacity property is equal to 0.
  • The Visibility property is equal to Visibility..::..Collapsed.
  • One of the ancestor objects of the Canvas is not visible.

Canvas Example

<Canvas Width="640" Height="480" Background="White">
    <Rectangle Canvas.Left="30" Canvas.Top="30"
           Fill="blue" Width="250" Height="150" />
    <Rectangle x:Name ="CanvasRect" Canvas.Left="60" Canvas.Top="60"  Height="50" Width="100" Fill="Red" ></Rectangle>
</Canvas>

Canvas Example

In Next we will discuss about Silverlight  Dock Panel Container

 

How LINQ Works

To use LINQ in your program you need a LINQ expression. Then then return type of LINQ expression is an iterator object that implements IEnumerable<T> and enumerating over the iterator object, LINQ performs its work. However this makes some questions about  LINQ

  • How LINQ works?
  • How LINQ execute statements?
  • How LINQ filter results?

LINQ works differently for different type of data type for example if you are using LINQ with database then it open database connections, perform SQL commands and return requested results back to you. In case of LINQ to objects LINQ simply perform uses for each loop to scan through the collection and return result back to you.

LINQ to objects is always slower as compare to comparable for each block, because this overhead is due to additional methods and delegate works. If you want to implement a advance search routine for in memory objects then un this case using LINQ will be a good idea as compare to for each block.

There are some point to remember while using LINQ to objects

  1. LINQ expressions work on objects that implement Enumerable<T> and LINQ
    expressions return objects that implement IEnumerable<T>.

ASP.NET State Management

As we all know that HTTP is a stateless protocol means when after each request client is disconnected from server and ASP.net discards objects that were created for the page. Drawback of this architecture is that you have to store the information between the server request while on the other side this architecture enable web applications to scale up and servers can responds to thousands of simultaneous requests without running out of server
memory.

ASP.net includes a variety of state management options. A developer can choose right option for state management option depending upon data you need to store, duration for which data has to be stored, data scope and security and performance considerations.

There are three options available for state management in ASP.net

  • View State
  • Query String
  • Custom Cookies
  • Caching
  • Profiles

In addition to this you can also write a custom state management module for your application and use database or file system for storing state information but this will bring some performance issues to your application because for retrieving and storing state information you need to establish database connections. 

we will discuss asp.net management options in more details in upcoming posts.

Overview of Language Integrated Query

Language Integrated Query is one of the feature that ship with .Net Framework 3.5. LINQ is a set of language extension that allows developers to write queries using full power programming that they are using, programming language might be C#, VB or any of the .Net supported language.  In a simplest form LINQ defines keywords that a developer can use to build queries. LINQ expressions allows developers to select, sort,filter, group and transform data.

Same LINQ expression can be used with different type of data sources. For example, LINQ to Objects, the simplest form of LINQ, allows you to query collections of in-memory objects. LINQ to DataSet performs the same feat with the in-memory DataSet. Even more interesting are the two LINQ flavors that let you access external data: LINQ to SQL, which allows you to query a SQL Server database without writing data access code, and LINQ to XML, which allows you to read an XML file without using .NET’s specialized XML classes.

Let’s start with how LINQ work with in memory collections. This is called LINQ to objects or simple LINQ. LINQ to objects allows developers to eliminate logic of for each loop.

For example, imagine you want to get a list of all website that have a word .net

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        ' Get the full collection of website from a helper method.
        Dim websitelist As List(Of Website) = Website.getWebsite
        'find a mathching website
        Dim matches As List(Of Website) = New List(Of Website)
        For Each websitename As Website In websitelist
            If websitename.websitename.Contains(".net") Then
                matches.Add(websitename)
            End If
        Next
    End Sub

Now perform the same task using LINQ

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
    Dim websites As New List(Of Website)
    Dim matches As IEnumerable(Of Website)
    matches = From websitename In websites Where websitename.websitename.Contains(".net") Select websitename

End Sub

Website Class Code

Public Class Website
    Public websitename As String
    Public websiteurl As String

    Public Sub New(ByVal websitename As String, ByVal websiteurl As String)
        Me.websitename = websitename
        Me.websiteurl = websiteurl

    End Sub
    Public Shared Function getWebsite() As List(Of Website)
        Dim weblist As New List(Of Website)
        Dim web1 As New Website("Microsoft", "http://microsoft.com")
        weblist.Add(web1)
        Dim web2 As New Website("MSDN", "http://msdn.microsoft.com")
        weblist.Add(web2)
        Dim web3 As New Website("All About ASP.Net", "http://allaboutasp.net")
        weblist.Add(web3)
        Dim web4 As New Website("ReadersZone", "http://readerszone.com")
        weblist.Add(web4)
        Dim web5 As New Website("ASP.net", "http://asp.net")
        weblist.Add(web5)
        Dim web6 As New Website("Silverlight", "http://silverlight.net")
        weblist.Add(web6)
        Return (weblist)

    End Function

End Class

Public Class Website
    Public websitename As String
    Public websiteurl As String

    Public Sub New(ByVal websitename As String, ByVal websiteurl As String)
        Me.websitename = websitename
        Me.websiteurl = websiteurl

    End Sub
    Public Shared Function getWebsite() As List(Of Website)
        Dim weblist As New List(Of Website)
        Dim web1 As New Website("Microsoft", "http://microsoft.com")
        weblist.Add(web1)
        Dim web2 As New Website("MSDN", "http://msdn.microsoft.com")
        weblist.Add(web2)
        Dim web3 As New Website("All About ASP.Net", "http://allaboutasp.net")
        weblist.Add(web3)
        Dim web4 As New Website("ReadersZone", "http://readerszone.com")
        weblist.Add(web4)
        Dim web5 As New Website("ASP.net", "http://asp.net")
        weblist.Add(web5)
        Dim web6 As New Website("Silverlight", "http://silverlight.net")
        weblist.Add(web6)
        Return (weblist)

    End Function

End Class