Click here to Skip to main content
15,887,676 members
Articles / Web Development / IIS

Skeleton for a Silverlight business application based on Ria Services and the Ria Services Class Library

Rate me:
Please Sign up or sign in to vote.
4.50/5 (7 votes)
7 Nov 2009CPOL13 min read 82.4K   1.5K   75  
This article presents the techniques and caveats of building Silverlight business applications. It describes breaking down applications into tiers, implementing a data access in N-tier applications, implementing a custom authentication, adding a support of https to Ria Services applications.
<controls:ChildWindow
  x:Class="BASample.Silverlight.LoginWindow"
  x:Name="childWindow" 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
  xmlns:dataform="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
  xmlns:activity="clr-namespace:System.Windows.Controls;assembly=ActivityControl"
  xmlns:app="clr-namespace:BASample.Silverlight"
  Width="400" 
  Title="Login"
  Style="{StaticResource LogRegWindowStyle}">
  
  <controls:ChildWindow.Resources>
    <Storyboard x:Name="ToLogin">
      <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="registerPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
        <DiscreteObjectKeyFrame KeyTime="00:00:00">
          <DiscreteObjectKeyFrame.Value>
            <Visibility>Visible</Visibility>
          </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="00:00:00.0750000">
        	<DiscreteObjectKeyFrame.Value>
        		<Visibility>Visible</Visibility>
        	</DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="00:00:00.1000000">
        	<DiscreteObjectKeyFrame.Value>
        		<Visibility>Collapsed</Visibility>
        	</DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
      </ObjectAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="registerPanel" Storyboard.TargetProperty="(UIElement.Opacity)">
        <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
        <EasingDoubleKeyFrame KeyTime="00:00:00.0750000" Value="0"/>
        <EasingDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0"/>
      </DoubleAnimationUsingKeyFrames>
      <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="loginPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
        <DiscreteObjectKeyFrame KeyTime="00:00:00">
          <DiscreteObjectKeyFrame.Value>
            <Visibility>Collapsed</Visibility>
          </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="00:00:00.0750000">
        	<DiscreteObjectKeyFrame.Value>
        		<Visibility>Visible</Visibility>
        	</DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
      </ObjectAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="loginPanel" Storyboard.TargetProperty="(UIElement.Opacity)">
      	<EasingDoubleKeyFrame KeyTime="00:00:00.0750000" Value="0"/>
      	<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
      </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Name="ToRegister">
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="registerPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
          <DiscreteObjectKeyFrame KeyTime="00:00:00.0750000">
        		<DiscreteObjectKeyFrame.Value>
        			<Visibility>Visible</Visibility>
        		</DiscreteObjectKeyFrame.Value>
        	</DiscreteObjectKeyFrame>
          <DiscreteObjectKeyFrame KeyTime="00:00:00.2500000">
          	<DiscreteObjectKeyFrame.Value>
          		<Visibility>Visible</Visibility>
          	</DiscreteObjectKeyFrame.Value>
          </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="loginPanel" Storyboard.TargetProperty="(UIElement.Opacity)">
          <EasingDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
          <EasingDoubleKeyFrame KeyTime="00:00:00.0750000" Value="0"/>
          <EasingDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
        <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="loginPanel" Storyboard.TargetProperty="(UIElement.Visibility)">
          <DiscreteObjectKeyFrame KeyTime="00:00:00.0750000">
        		<DiscreteObjectKeyFrame.Value>
        			<Visibility>Visible</Visibility>
        		</DiscreteObjectKeyFrame.Value>
        	</DiscreteObjectKeyFrame>
          <DiscreteObjectKeyFrame KeyTime="00:00:00.1000000">
          	<DiscreteObjectKeyFrame.Value>
          		<Visibility>Collapsed</Visibility>
          	</DiscreteObjectKeyFrame.Value>
          </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="registerPanel" Storyboard.TargetProperty="(UIElement.Opacity)">
          <EasingDoubleKeyFrame KeyTime="00:00:00.0750000" Value="0"/>
          <EasingDoubleKeyFrame KeyTime="00:00:00.2500000" Value="1">
          	<EasingDoubleKeyFrame.EasingFunction>
          		<CubicEase EasingMode="EaseIn"/>
          	</EasingDoubleKeyFrame.EasingFunction>
          </EasingDoubleKeyFrame>
      </DoubleAnimationUsingKeyFrames>
    </Storyboard>
  </controls:ChildWindow.Resources>

  <Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <StackPanel x:Name="loginPanel" Grid.Row="0">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition/>
          <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <StackPanel Style="{StaticResource LoginControlsStackPanelStyle}">
          <!-- username textbox-->
          <StackPanel Style="{StaticResource LoginControlStyle}">
            <TextBlock Text="Username" Style="{StaticResource LoginTextStyle}"/>
            <TextBox x:Name="loginUserNameBox" TextChanged="LoginUserNameBox_TextChanged" Style="{StaticResource LoginTextBoxStyle}"/>
          </StackPanel>
          <!-- password textbox-->
          <StackPanel Style="{StaticResource LoginControlStyle}">
            <TextBlock Text="Password" Style="{StaticResource LoginTextStyle}"/>
            <PasswordBox x:Name="loginPasswordBox" PasswordChanged="LoginPasswordBox_PasswordChanged" Style="{StaticResource LoginPSBoxStyle}"/>
          </StackPanel>
        </StackPanel>

        <StackPanel Style="{StaticResource RegisterLoginLinkPanelStyle}" Grid.Row="1">
          <TextBlock Text="Not yet registered?" Style="{StaticResource CommentStyle}"/>
          <HyperlinkButton x:Name="registerNow" Content="Register Now" Click="RegisterNow_Click"/>
        </StackPanel>

        <Button Content="Cancel" Click="CancelButton_Click" Margin="0,0,0,1" Grid.Row="1" Style="{StaticResource RegisterLoginButtonStyle}"/>
        <Button x:Name="loginButton" Content="OK" Click="LoginButton_Click" Grid.Row="1" Style="{StaticResource RegisterLoginButtonStyle}"/>

      </Grid>
    </StackPanel>

    <StackPanel x:Name="registerPanel" Grid.Row="0" Visibility="Collapsed">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition />
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <activity:Activity x:Name="activity">
          <dataform:DataForm x:Name="registerForm" Header="Please enter required information for account creation" AutoGenerateFields="False" AutoEdit="True" CommandButtonsVisibility="None" Grid.Row="0" Style="{StaticResource DataFormStyle}">
            <dataform:DataForm.EditTemplate>
              <DataTemplate>
                <StackPanel Orientation="Vertical">
									<dataform:DataField Label="Name">
										<TextBox Text="{Binding Name, Mode=TwoWay}" />
									</dataform:DataField>

                  <dataform:DataField Label="Password">
                    <app:PasswordControl PasswordText="{Binding Password, Mode=TwoWay}"/>
                  </dataform:DataField>

                  <dataform:DataField Label="Confirm password">
                    <app:PasswordControl PasswordText="{Binding ConfirmPassword, Mode=TwoWay}"/>
                  </dataform:DataField>

                  <dataform:DataField Label="Email">
                    <TextBox Text="{Binding Email, Mode=TwoWay}" />
                  </dataform:DataField>

                  <dataform:DataField Label="Question">
                    <TextBox Text="{Binding Question, Mode=TwoWay}" />
                  </dataform:DataField>

                  <dataform:DataField Label="Answer">
                    <TextBox Text="{Binding Answer, Mode=TwoWay}" />
                  </dataform:DataField>
                </StackPanel>
              </DataTemplate>
            </dataform:DataForm.EditTemplate>
          </dataform:DataForm>
        </activity:Activity>
        <StackPanel Style="{StaticResource RegisterLoginLinkPanelStyle}" Grid.Row="1">
          <TextBlock Text="Already registered?" Style="{StaticResource CommentStyle}" />
          <HyperlinkButton x:Name="backToLogin" Content="Back to Login" Click="BackToLogin_Click"/>
        </StackPanel>

        <Button Content="Cancel" Click="CancelButton_Click" Margin="0,0,0,1" Grid.Row="1" Style="{StaticResource RegisterLoginButtonStyle}"/>
        <Button x:Name="registerButton" Content="OK" Click="RegisterButton_Click" Grid.Row="1" Style="{StaticResource RegisterLoginButtonStyle}"/>

      </Grid>

    </StackPanel>

  </Grid>

</controls:ChildWindow>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader www.maxpaulousky.com
Belarus Belarus
Max currently is a senior developer at software company.

He lives with his wife Tatiana and son Zakhar (4 yrs) in Minsk, Belarus, but they dream to live in New Zealand.

Comments and Discussions