Saturday 19 November 2011

WCF With Silverlight

Here is an example of WCF services with Silverlight performing some mathematical operations like addition, substraction, etc.

Lets begin :)

1) Open Visual Studio -> Click New Project -> Select Silverlight from Project Type and then Specify Name and Location from New Project Window.

2) In New Silverlight Application, Select Asp.Net Web Application Project As New Web Project Type -> Ok.

3) Open Expression Blend for designing UI of application, it is easy to create user interface in blend.

//MainPage.xaml



<UserControl
    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"  x:Class="SLMathsDummy.MainPage"
    d:DesignWidth="600" d:DesignHeight="500">
    
<Grid x:Name="LayoutRoot" Background="#FFF8D1D1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.373*"/>
            <ColumnDefinition Width="0.28*"/>
            <ColumnDefinition Width="0.347*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.144*"/>
            <RowDefinition Height="0.08*"/>
            <RowDefinition Height="0.08*"/>
            <RowDefinition Height="0.128*"/>
            <RowDefinition Height="0.08*"/>
            <RowDefinition Height="0.16*"/>
            <RowDefinition Height="0.328*"/>
        </Grid.RowDefinitions>

        <Button x:Name="btnAddition" HorizontalAlignment="Right" Margin="0,0,96,58" Width="75" Grid.Row="5" Content="Addition" FontWeight="Bold" VerticalAlignment="Bottom" Grid.Column="1">
            <Button.Foreground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FFF00B0B" Offset="1"/>
                </LinearGradientBrush>
            </Button.Foreground>
        </Button>
       

<Button x:Name="btnSubstract" Margin="96,0,0,0" Grid.Column="1" Grid.Row="5" Content="Substract" FontWeight="Bold" VerticalAlignment="Top" Width="75" HorizontalAlignment="Left" d:LayoutOverrides="Width">
            <Button.Foreground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FFF00B0B" Offset="1"/>
                </LinearGradientBrush>
            </Button.Foreground>
        </Button>
        
<Button x:Name="btnMultiply" Margin="0,0,93,2" Grid.Column="1" Grid.Row="5" Content="Multiply" FontWeight="Bold" VerticalAlignment="Bottom" Width="75" HorizontalAlignment="Right" d:LayoutOverrides="Width">
            <Button.Foreground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FFF00B0B" Offset="1"/>
                </LinearGradientBrush>
            </Button.Foreground>
        </Button>
        
<Button x:Name="btnDivide" HorizontalAlignment="Left" Width="75" Grid.Column="1" Grid.Row="5" Content="Divide" FontWeight="Bold" VerticalAlignment="Bottom" Margin="93,0,0,0">
            <Button.Foreground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FFF00B0B" Offset="1"/>
                </LinearGradientBrush>
            </Button.Foreground>
        </Button>
        
<TextBlock x:Name="txbFNumber" HorizontalAlignment="Right" Margin="0,8,4,16" Grid.Row="1" Text="First No :" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="#FFF80D0D"/>
       
<TextBlock x:Name="txbSNumber" HorizontalAlignment="Right" Margin="0,8,4,16" Grid.Row="2" Text="Second No :" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="#FFF21111"/>
      
<TextBlock x:Name="txbResult" HorizontalAlignment="Right" Margin="0,8,8,16" Grid.Row="4" Text="Result :" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="#FFFA0D0D" FontWeight="Bold"/>
       
<TextBlock x:Name="txbResultSet" HorizontalAlignment="Left" Margin="0,8,4,16" Grid.Column="1" Grid.Row="4" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="#FF102EEE" FontWeight="Bold"/>
        
<TextBox x:Name="txtFNo" Margin="8,8,0,8" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="#FF102EEE" Width="300"/>
       
<TextBox x:Name="txtSNo" Margin="8,8,0,8" Grid.Column="1" Grid.Row="2" TextWrapping="Wrap" d:LayoutOverrides="Height" Foreground="#FF102EEE" Width="300"/>
   
</Grid>
</UserControl>

Note : Don't worry for namespace that are in <UserControl>, they will appear automatically when you drag controls in design interface.

4) Click on Add -> New Item -> Select Silverlight-enabled WCF service. Default its name is Service1.svc.





5) //Service1.svc.cs

Replace existing Operation Contract DoWork() by following codes.

 [OperationContract]
        public int Addition(int num1, int num2)
        {
            return num1+num2;
        }

        [OperationContract]
        public int Substract(int num1, int num2)
        {
            return num1-num2;
        }

        [OperationContract]
        public int Multiply(int num1, int num2)
        {
            return num1*num2;
        }

        [OperationContract]
        public int Divide(int num1, int num2)
        {
            return num1/num2;
        }

 6) Add Service Reference



7) //MainPage.xaml.cs

private void btnAddition_Click(object sender, RoutedEventArgs e)
{
            int num1, num2;
            ServiceReference1.SLWCFAddServiceClient addService = new  ServiceReference1.SLWCFAddServiceClient();
            addService.AdditionCompleted += new EventHandler<SLWCFAdd.ServiceReference1.AdditionCompletedEventArgs>(addService_AdditionCompleted);
            num1 = Convert.ToInt32(txtFNo.Text.ToString());
            num2 = Convert.ToInt32(txtSNo.Text.ToString());
            addService.AdditionAsync(num1, num2); 
}


public void addService_AdditionCompleted(object s, ServiceReference1.AdditionCompletedEventArgs e)
        {
            txbResultSet.Text = e.Result.ToString();
        }

       
private void btnSubstract_Click(object sender, RoutedEventArgs e)
        {
            int num1, num2;
            ServiceReference1.SLWCFAddServiceClient subService = new SLWCFAdd.ServiceReference1.SLWCFAddServiceClient();
            subService.SubstractCompleted +=new EventHandler<SLWCFAdd.ServiceReference1.SubstractCompletedEventArgs>(subService_SubstractCompleted);
            num1 = Convert.ToInt32(txtFNo.Text.ToString());
            num2 = Convert.ToInt32(txtSNo.Text.ToString());
            subService.SubstractAsync(num1, num2);
        }

       
public void subService_SubstractCompleted(object s, ServiceReference1.SubstractCompletedEventArgs e)
        {
            txbResultSet.Text = e.Result.ToString();
        }

       
private void btnMultiply_Click(object sender, RoutedEventArgs e)
        {
            int num1, num2;
            ServiceReference1.SLWCFAddServiceClient multiService = new SLWCFAdd.ServiceReference1.SLWCFAddServiceClient();
            multiService.MultiplyCompleted += new EventHandler<SLWCFAdd.ServiceReference1.MultiplyCompletedEventArgs>(multiService_MultiplyCompleted);
            num1 = Convert.ToInt32(txtFNo.Text.ToString());
            num2 = Convert.ToInt32(txtSNo.Text.ToString());
            multiService.MultiplyAsync(num1, num2);
        }

 public void multiService_MultiplyCompleted(object s, ServiceReference1.MultiplyCompletedEventArgs e)
        {
            txbResultSet.Text = e.Result.ToString();
        }

private void btnDivide_Click(object sender, RoutedEventArgs e)
        {
            int num1, num2;
            ServiceReference1.SLWCFAddServiceClient divService = new SLWCFAdd.ServiceReference1.SLWCFAddServiceClient();
            divService.DivideCompleted += new EventHandler<SLWCFAdd.ServiceReference1.DivideCompletedEventArgs>(divService_DivideCompleted);
            num1 = Convert.ToInt32(txtFNo.Text.ToString());
            num2 = Convert.ToInt32(txtSNo.Text.ToString());
            divService.DivideAsync(num1, num2);
        }

public void divService_DivideCompleted(object s, ServiceReference1.DivideCompletedEventArgs e)
        {
            txbResultSet.Text = e.Result.ToString();
        }


8) Run the application.





Monday 14 November 2011

LINQ Interview Questions And Answers

Here, some common LINQ interview questions which asked by the interviewer.  
 

What is use of ‘Distinct’ in a LINQ ?

It removes duplicate values from result set.

What is different between LINQ and Stored Procedure?

  •  We can debug LINQ as it is part of .Net, whereas Stored procedure can’t be.
  •  Deployment is easy with LINQ as everything compiled into DLL whereas with Stored procedure script is required for deployment.
  •  At compile time we can find error, if any in LINQ but it not possible with Stored procedure.
What is role of DataContext classes in LINQ?
  
DataContext  acts as a bridge between a  SQL Server database and the LINQ to SQL. It contains the connection string  and functions for accessing the database and for also  changing  the data in the database.   

In LINQ, ‘Select’ comes after ‘ From’, why?

In any programming language, variable defines first then conditions specifies. In LINQ also, all variables declared first by using ‘Select’ clause then ‘From’ clause is used for define conditions.

What is the extension of LINQ to SQL file ?

It is .dbml.

Disadvantage of LINQ over Stored procedure?

Stored procedure compiles one time and executed every time whereas LINQ compiled everytime , so Stored Procedure is faster as compare to LINQ.


Friday 11 November 2011

WPF Interview Questions And Answers

Here, some common WPF interview questions which asked by the interviewer. 

Explain WPF?

Windows Presentation Foundation (WPF) is UI framework, used to create rich user experience application. It introduced in .NET 3.0. WPF supports 2D graphics, 3D graphics, animations, documents and multimedia. 

What do you mean by dependency properties in WPF?
Dependency properties are properties of one class and used by another class.
Let’s understand by an example:
<Ellipse Height=”70” Width=”70” Canvas.Right=”20” Canvas.Top=”30” />
Here ‘Canvas.Right’ and ‘Canvas.Top’ are dependency properties as it used by Ellipse to specify position within Canvas though it’s not properties of Ellipse.
Which namespace is using for animations and 3D graphics in WPF?

System.Windows.Media  namespace is using.

Which operating systems support WPF?
  •  Windows XP Service Pack 2 or later
  •  Windows7
  •  Windows Vista
How many layouts supported in WPF?
  •  Grid
  •  Stack Panel
  •  Dock Panel
  •  Wrap Panel
  •  Canvas Panel
Which type of documents supported by WPF?
WPF supports two types of documents, ‘Fixed Format Documents’ and ‘Flow Format Documents’.  Fixed format document is like PDF. It displays contents regardless of screen resolution and size.  Flow format document adjust content with respect to screen resolution and size.
What are advantages of WPF over Windows applications?
WPF has following capabilities:
  1. Supports 2D and 3D vector graphics.
  2. Animation
  3. Multimedia
  4. Fixed and Flow format documents
  5. Having all capabilities of Html and Flash.
  6. UI separates from code.




Wednesday 9 November 2011

WCF Interview Questions And Answers

Here, some common WCF interview questions which asked by the interviewer. 

Explain briefly about WCF?
WCF is a programming platform and runtime system for building, configuring and deploying network-distributed services. It is latest service oriented technology. Interoperability is fundamental characteristic of WCF. WCF is combined feature of Web Service, Remoting, MSMQ, and COM+. WCF provides a common platform for all .NET communication.

What are different technologies involved in WCF?

There are mainly five technologies involved in WCF, these are :
  1. WSE [WS*] - Protocol Support.
  2. Messaging  - Message oriented programming.
  3. .Net Remoting - Extensibility location transparency.
  4. Enterprise Service - Attribute based programming.
  5. ASMX - Interop with other platforms.
What are advantages of WCF?

Advantages of WCF are :
  1. WCF is interoperable with other services but .Net Remoting requires client and service in .Net.
  2. WCF service provides better reliability and security as compare to Web Services.
  3. In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small change in the configuration will make your requirement.
Brief about WCF Hosting?
There are three ways of hosting WCF service :
Self Hosting
IIS Hosting
WAS(Windows Activation Service)
Explain address and all types of address in WCF?
Address describes where WCF service is hosted. Address is URL that client uses to connect to desired service.
Here is an example :

What is Binding in WCF?
 

Binding describes how client will communicate with services. There are different protocols available to communicate to client. Binding has several  characteristics :

Transport - Define base protocol to be used like HTTP, Named Pipes, TCP and MSMQ. 

Encoding(Optional) - Three types of encoding available - Text, Binary or Message Transmission Optimization Mechanism(MTOM). MTOM is interoperable message format that allows the effective transmission of attachments or large message. 

Protocol(Option) - Defines information to be used in Binding such as security transaction or reliable messaging capability.

What are types of Binding available in WCF? 
BasicHttpBinding It uses SOAP over HTTP.
WsHttpBinding It uses SOAP over HTTP, it also supports reliable message transfer.
NetTcpbinding It uses SOAP over TCP, but server and client should be in .Net.
NetNamedPipesBinding It uses SOAP over Named Pipes.

Explain contract and all types of contract in WCF?
 
Contract is platform-neutral and standard way of describing what services does. In WCF, all services are exposed as contract. There are four types of contracts :
Service Contract It describes operation provided by service. A service should contain at least one service contract. Service Contract is defined by using [ServiceContract] attribute , it is similar to [WebMethod] of Web Services.

Data Contract It describes data exchange between service and client. Data Contract is defined using [DataContract] and [DataMember] attribute.
Message Contract It transfers information from service to client. WCF uses SOAP message format for communication.
Fault Contract It handles and convey error message to the client when service get error.
What is concept of endpoint in WCF?
WCF service expose endpoints by which service is available to client.Endpoint is nothing but consists of ABC that is Address, Binding and Contract.

What is WCF Runtime?

WCF  runtime is set of objects for sending and receiving message.

What is Message in WCF?

WCF message is the unit of data exchange between client and service. It consists of several parts, including a body and header.

Difference between WCF and Web Service?
 

1) Web Services support hosting in IIS whereas WCF support hosting in IIS, WAS and Self-hosting.
2) Web Services can be invoked by Http whereas WCF service can be invoked by Http, Tcp, Named Pipes, MSMQ.
3) WCF Services are more reliable and secure as compare to Web Services.
4) WCF Services are more flexible as we make a new version of service we just have to expose a new endpoint.
5) In Web Service, [WebMethod] attribute specifies the method exposed to client. In WCF [OperationContract] attribute represents the method.

What is Service Host?

Service Host object is in process of  hosting the WCF service and registering endpoints. It loads the service configuration  endpoints, apply the settings. System.ServiceModel.ServiceHost namespace holds this object. This object is created while self hosting the WCF service.

There is scenerio, when one client has to access service SOAP using Http and other client have to access Binary using TCP, how can you acheive?

This can be acheived by adding extra endpoint in configuration file.

<endpoint address="http://locahost:8090/Service" contact="IMathService" binding="wsHttpBinding"/>
<endpoint address="net.tcp://locahost:8080/Service" contact="IMathService" binding="netTcpBinding"/>




  

Silverlight Animation

For creating animation in Silverlight, we have to change object's properties like size, position, color etc over period of time.

Here is a simple example of button-growing where storyboard applies a DoubleAnimation to the Width property of a button.

1) Open Visual Studio -> Click File -> New Project -> In Project dialog box :- Select Silverlight application -> Ok.

2) Click Assets -> Control -> Button.

//MainPage.xaml
<Grid x:Name="LayoutRoot">
        <Button x:Name="btnGrow" Width="160" Height="30" Click="btnGrow_Click"
Content="Keep Growing"></Button>
    </Grid>

For Creating Animation, write :

 <UserControl.Resources>
        <Storyboard x:Name="storyboard">
            <DoubleAnimation Storyboard.TargetName="btnGrow" Storyboard.TargetProperty="Width"
From="160" To="300" Duration="0:0:5"></DoubleAnimation>
        </Storyboard>
    </UserControl.Resources>

//MainPage.xaml.cs
private void btnGrow_Click(object sender, RoutedEventArgs e)
        {
            storyboard.Begin();
        }

3) Run the application,



On Clicking Button :


Wednesday 2 November 2011

Silverlight Interview Questions And Answers


Here, some common Silverlight interview questions which asked by the interviewer.

What is Xaml in Silverlight?

Xaml[Extensible Application Markup Language], it is pronounced as Zammel. Xaml is a Xml based language, it contains elements that can be nested in any arrangement.

How style works with Silverlight?

Style is collection of property value that apply to an element. First define the style in App.xaml.
<Application.Resource>
        <Style x:key="MyButton" TargetType="Button">
                 <Setter Property="FontFamily" Value="Verdana" />
                 <Setter Property="FontSize" Value="36" />
        </Style>
</Application.Resource>

Apply style to Button.
<Button Style="{StaticResource MyButton}" Content="My Button" ></Button>

What are the programming languages in which you can implement behavior of Silverlight application?

C# or Visual Basic programming language can be used.
 
Explain about Silverlight plug-in?

Silverlight plug-in is easy to download and takes few second to install on client's system. It is necessary to access Silverlight object that is embedded in web page. User has to download this plug-in for only one time.

What is ClientBin folder in Silverlight application?

ClientBin folder is folder in Silverlight application which store .xap file.

What is .xap file?

A .xap file is a created when Silverlight project is built. It includes AppManifest.xaml, assembly of Silverlight project and resource files referred by Silverlight application. 

What files are contained by .xap file?

A .xap file contains application manifest [AppManifest.xaml] and all the DLLs required by the application.
 
What is Silverlight SDK?

Silverlight SDK contains samples, documentations, libraries and tools for developing Silverlight application.
Silverlight SDK is not necessary for creating Silverlight application but its makes development easy.

What is official name of Silverlight?

It is WPF/E.

Silverlight is developed in which languages?

Silverlight is developed in C# and C++. 

Expression Studio orVisual Studio, which one better to use for developing Silverlight application?

Expression Studio and Visual Studio both are used for creating Silverlight application.If Silverlight application has graphics and visual elements then its good to work with Expression Studio. If Silverlight application has programming coding then its good to use Visual Studio.

For Windows,what are system requirement for Silverlight?

Operating System - Windows 7, Windows Vista, Windows XP SP2.
Processor - Intel Platinum III
RAM - 128MB

Is it possible to consume WCF and Web Services in Silverlight application?

Yes, it is possible.


What are those platforms which supports Silverlight?

1. Windows XP Service Pack 2
2. Windows 2000
3. Windows Vista
4. Windows Server 2003
5. Mac OS
6. Linux Moonlight

What are those browsers which supports Silverlight?


Internet Explorer 6,7,8
Mozilla Firefox 2,3
Safari 3,4
Google Chrome



What are deep zoom and deep zoom  composer?

Deep zoom composer is tool in Silverlight which make image with deep zoom feature. Actually Deep zoom is feature in Silverlight which zoom in and out of images rapidly without affecting the performance of application.
Its Deep zoom composer which creates high resolution composition for image for smooth zooming.

What are differences between Silverlight and WPF?

1. Silverlight is used for developing RIA for web application whereas WPF is using for windows applications.
2. Silverlight supports cross-browser, cross-platform whereas WPF supports windos only.
3. Silverlight is add-on machnism for most of the browsers but it is necessary to run Silverlight plug-in  once on client's system. But with WPF, it is necessary to install WPF client application on client's system.
4. Silverlight is small subset of .NET framework to optimized its size. WPF has full access to main .NET framework and its assemblies.


What are differences between Silverlight and Asp.Net? 
1. Silverlight runs on client's system whereas Asp.Net runs on the server.
2. When an event fires, Silverlight handles the event on the client whereas in Asp.Net, the browser will make an Http Post to the server.
3. Silverlight can't work directly with database, it consumes data from web service whereas Asp.Net supports working with database.

How Silverlight 4 is different from Silverlight 3?

There are a lot of new features in Silverlight 4 that are not present in Silverlight 3 :-

  •  Print Support
  •  WebCam / Microphone Support
  •  Mouse right click event handling
  •  RichTextArea Control
  •  Multicast network support
  •  Silverlight hosting in HTML 4
  •  Google Chrome support
        
         
         
        
         
      
     
      

Silverlight Styles

Styles in Silverlight is a collection of property values that we can apply to any element in one easy step.

Lets Define Style first :)

For example, we want to give some style like font and foreground color to Button.


//App.xaml
<Application.Resources>    
        <Style x:Key="ButtonStyle" TargetType="Button">
            <Setter Property="FontFamily" Value="Georgia" />
            <Setter Property="FontSize" Value="32" />
            <Setter Property="Foreground" Value="SlateGray" />
            <Setter Property="Padding" Value="20" />
            <Setter Property="Margin" Value="10" />
        </Style>
</Application.Resources>

Apply Style to Button :-

//MainPage.xaml
<Button VerticalAlignment="Top" Content="My Button Style" Style="{StaticResource ButtonStyle}" Height="81" />



Tuesday 1 November 2011

Silverlight E-Books

Download Free Silverlight E-Books From Here :


Silverlight 4 Dummies :- http://www.free-ebooks-download.org/free-ebook/dotnet/ASP.NET/microsoft-silverlight-4-for-dummies.php



Silverlight 4 Unleashed :- http://www.ebookee.biz/silverlight-4-unleashed.html



Silverlight Elements

AutoCompleteBox :-
 
It is a Textbox that provides possible matches when user types.

Here is an example that uses the set of twelve calendar months:

//MainPage.xaml
<input:AutoCompleteBox Margin="170,124,191,0" VerticalAlignment="Top" Name="txtMonth" Width="250" />

//MainPage.xaml.cs
string[] monthList = {"January", "February", "March", "April","May", "June", "July", "August", "September","October", "November", "December"};
txtMonth.ItemsSource = monthList;

Lets run the application and type 'j' , you will see this :)



TextBlock :-

In Silverlight we have Label but we are using mostly TextBlock for showing blocks of formatted text.

//MainPage.xaml
 <TextBlock>This is text</TextBlock>
or, <TextBlock Text="This is text"></TextBlock>



HyperLinkButton :-

If we use text in HyperLinkButton, it appears Blue by default, but its not underlined [use Text Decoration property if you want that effect]. On 'Mouse Over', mouse cursor changes to pointing hand [you can override this property by setting cursor property].


RadioButton :-
 
If we have all  Radio Buttons in one StackPanel, they are in one Group. There is 'GroupName' property for Radio Buttons for grouping.

Here is an example :)

//MainPage.xaml
<StackPanel>
            <RadioButton Content="Group 1"></RadioButton>
            <RadioButton Content="Group 2"></RadioButton>
            <RadioButton Content="Group 3"></RadioButton>
</StackPanel>


ToolTip :-

It is a content control, you can populate anything inside ToolTip. You can use ToolTipServices to configure a tooltip for an existing element.

Note : We can assign name to tooltip and can handle it programmatically.

//MainPage.xaml
<Button Content="I have a fancy tooltip" Width="200" Height="30">
            <ToolTipService.ToolTip>
                <StackPanel>
                    <TextBlock Margin="3" Text="Image and text"></TextBlock>
                    <Image Source="HappyFace.jpg"></Image>
                    <TextBlock Margin="3" Text="Image and text"></TextBlock>
                </StackPanel>
            </ToolTipService.ToolTip>
        </Button>



ListBox :-

You can use ListBoxItem inside ListBox for adding items.

//MainPage.xaml
<ListBox>
            <ListBoxItem>
                <Image Source="Happyface.jpg"></Image>
            </ListBoxItem>
            <ListBoxItem>
                <Image Source="SadFace.jpg"></Image>
            </ListBoxItem>
</ListBox>

Here is an example that uses nested StackPanel to combine text and image content:

<ListBox HorizontalAlignment="Center" Width="250" Height="100">
            <StackPanel Orientation="Horizontal">
                <Image Source="Happyface.jpg" Width="30" Height="30"></Image>
                <TextBlock VerticalAlignment="Center" Text="A happy face"></TextBlock>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Image Source="SadFace.jpg" Width="30" Height="30"></Image>
                <TextBlock VerticalAlignment="Center" Text="A sad face"></TextBlock>
            </StackPanel>
</ListBox>