WCF Azure Silverlight Calculator

This sample creates a simple WCF calculator service and builds a Silverlight client for it. The client is then hosted alonside the service in the Azure fabric.

 
 
 
 
 
4 Star
(4)
5,454 times
Add to favorites
4/27/2011
E-mail Twitter del.icio.us Digg Facebook

Solution explorer

C#
VB.NET
<UserControl x:Class="SilverlightCalculator.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" Width="300" Height="300" Margin="20">
    <UserControl.Resources>
        <Style TargetType="Button" x:Key="CalculatorButton">
            <Setter Property="FontSize" Value="20"/>
        </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>

        <TextBox Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4" FontSize="30" x:Name="display" TextAlignment="Right" />
        <Button Grid.Column="0" Grid.Row="1" Click="Add_Didgit" Content="1" Style="{StaticResource CalculatorButton}" />
        <Button Grid.Column="1" Grid.Row="1" Click="Add_Didgit" Content="2" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="2" Grid.Row="1" Click="Add_Didgit" Content="3" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="0" Grid.Row="2" Click="Add_Didgit" Content="4" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="1" Grid.Row="2" Click="Add_Didgit" Content="5" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="2" Grid.Row="2" Click="Add_Didgit" Content="6" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="0" Grid.Row="3" Click="Add_Didgit" Content="7" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="1" Grid.Row="3" Click="Add_Didgit" Content="8" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="2" Grid.Row="3" Click="Add_Didgit" Content="9" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="0" Grid.Row="4" Click="Add_Didgit" Content="0" Style="{StaticResource CalculatorButton}"/>

        <Button Grid.Column="3" Grid.Row="1" Click="Do_Operation" Content="+" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="3" Grid.Row="2" Click="Do_Operation" Content="-" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="3" Grid.Row="3" Click="Do_Operation" Content="*" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="3" Grid.Row="4" Click="Do_Operation" Content="/" Style="{StaticResource CalculatorButton}"/>
        <Button Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="2" Click="Do_Operation" Content="=" Style="{StaticResource CalculatorButton}"/>

    </Grid>
</UserControl>