A Simple Silverlight Image Rotator

by Bobbi Perreault 24. April 2009 19:05
Share on Facebook

There are a million and three photo display Silverlight applications out there.  And here's one more.  I just wanted my own.  I wanted one that I can load up the images in Xaml and push go with.  Here it is,

First, define all my images in Xaml

  <Canvas x:Name="ImageDisplay" Width="600" Height="450">
        <Image Margin="0,0,0,0" Source="images/IMG_1989.JPG"  Width="600" Height="450" x:Name="image" Opacity="0" />
        <Image Margin="0,0,0,0" Source="images/IMG_1990.JPG"  Width="600" Height="450" Opacity="0"/>
        <Image Margin="0,0,0,0" Source="images/IMG_1991.JPG"  Width="600" Height="450" Opacity="0"/>
 </Canvas>

 

Second, wire it up in the code behind:

public Page()        
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Page_Loaded);
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
//start the animations
beginTheFirst();
}
private void beginTheFirst()
{
int icnt = 0;
//tell the imageRotater what it will manage.
Canvas container = ImageDisplay;
mcarousel = new imageRotater();
for (int i = container.Children.Count - 1; i >= 0; i--)
{
FrameworkElement childFE = container.Children[i] as FrameworkElement;
if (childFE is Image)
{
mcarousel.CreateItem( childFE, "resources" + icnt.ToString(), this);
icnt++;
}
}
//start the first.
mcarousel.StartRotating();
}

Everything hinges on this SwitchImage function, but that’s all.  The objects manage themselves after that.

public void SwitchImage(FrameworkElement image, FrameworkElement oldimage)

{

if (image == null)

return;

if (oldimage != null)

{

FadeOutEffect fadeOut = new FadeOutEffect();

fadeOut.Start(oldimage);

}

mImage = image;

FadeInEffect fadeIn = new FadeInEffect();

fadeIn.Start(image);

}

If you’d like the source, you can download it here: http://www.faxt.com/silverlight/code/countrylife.zip

Tags:

Silverlight Line of Business Application, Transport Layer

by Bobbi Perreault 18. April 2009 01:49
Share on Facebook

At least I’m trying.  And that’s how I’ll get better, too.

In Silverlight 2 the coordination between a web application and the Silverlight client application application ( one that doesn’t use Astoria  Data Services  ) needs to be built by the application programmer.

In a few of my Silverlight projects, I’ve used the method I’ll describe below and it’s working fine.  I have to say though that my user-base and simultaneous user count isn’t large so I haven’t tested this method under high volume situations.

Here is an architectural view of how the software packages and sends data from Silverlight client to Web Server.

The package of source code which is presented with this article is a LOB application I’m writing for EZBurn ManufacturingEZBurn’s app will at some point consist of tools to manage customer communications, production drawings, production line processes, and overall health of operations.  These pieces were pulled out of this demo package, but I’ve left all the code which is responsible for communicating back and forth to the web server and business logic containers.  There’s a Google Maps sample for you if you drill down to a person record, it’s kind of interesting.  Another piece I left in is the Silverlight History component.  That ensures your ability to use Deep Linking.

I discussed the serialization and compression sources in a previous blog post:  http://faxt.com/blog/post/2008/08/SOA---Server-to-Silverlight-and-Back.aspx

Please feel free to email me with questions – I have to apologize for being so short on this post, but MAN – there aren’t enough hours in the day for my spring yard cleaning and today is a bright, sunny day just made for gardening.

Here’s the source

Here’s the running application so you can see it in action

 

 

 

 

 

Tags:

A Silverlight V2 Code Gen Template for Subsonic

by Bobbi Perreault 16. April 2009 02:20
Share on Facebook

I wrote a blog post about using Subsonic to speed up Silverlight 2 projects.  This is important in Silverlight 2 because of it’s limited (make that non-existent) support for working with already existing business objects.  Thankfully, this problem will evaporate in SLV3 – or at least that’s my  understanding. 

In the mean time, I’ve written a lot of code to help me get my data securely from server to client and back again.  To reduce duplication of code, I used Subsonic project and some custom templates to generate my Silverlight business objects (ok, property bags), my Silverlight Xaml and Xaml code behind, and also to generate my serverside BO/Property bags.

This blog post is written to provide details on how I incorporated my customized templates into the Subsonic project that I have.  And no, sorry, this isn’t the latest version of Subsonic.  And Oops.  I don’t know if these procedures will need modified for the latest Subsonic.  Probably.  Anyway, here’s a link to the finished Subsonic project, 17 mb download, just so you can see how the code went together.

There’s a web app that comes with Subsonic, called SubSonicCentral.  Here is where you can play with the code gen features of SubSonic, and this is where I placed my controlling code to be able to generate SL templates.  The page, Generators.aspx, has a new usercontrol tag:

<%@ Register src="inc/SilverlightXAMLGenerator.ascx" TagName="XAMLGenerator" TagPrefix="uc3" %>

<uc3:XAMLGenerator ID="SilverlightXAMLGenerator1" runat="server" />

SilverlightXAMLGenerator.ascx is where the entry point is for this code.  It started as a clone of ClassGenerator.ascx which is a SubSonic file, really the only differences are in the identity of the templates used and the code gen type.

The key function is the click event handler for btnGo.

protected void btnGo_Click(object sender, EventArgs e)

I have no clue where to start to explain this.  So all I’ll add here are the names of items added to this project to support one new template.    You can download the SubSonic project above and use search to find the specific spots. 

I added to the project:

  • A template file for each language supported (not all finished).  These files go in folder:  SubSonic\CodeGeneration\Templates.  CS_SilverlightXAML.CodeBehind.aspx and VB_SilverlightXAML.CodeBehind.aspx
  • FileExtension.XAML:  this is a constant which identifies the output filename
  • CodeService.BuildSilverlightCodeBehindTemplate(item.Value, className, language, provider);
  • TemplateType.SilverlightCodeBehind
  • this was modified to add the new template:   private static string GetTemplateText(TemplateType t, ICodeLanguage language)

Tags:

Why I Should Change My Name

by Bobbi Perreault 14. April 2009 04:33
Share on Facebook

It's nice to have others recognize that you've contributed in some way.  I just LOVE it when someone thanks me.  The only problem is, my name isn't Bobby Perrault.  It's Bobbi Perreault.  I would just like in some way to tie the two names together, not to make their life harder, but to enable others who may want more information on Bobby Perrault to be able to find it.  So - here it is, Google - come on down and make the connection for me.

 Thank-you, and Happy SPRING!!!!!!!

Tags:

 

RSS Feed FriendFeed