Silverlight.FX Updated for Silverlight 3

First build of Silverlight.FX on top of Silverlight 3 with updates/enhancements ready - new features include ApplicationContext class, new Float/Spin3D effects, and Back/Forward integration.

This is a quick blog post announcing the availability of Silverlight.FX version 3.1 which is sync’d up to Silverlight 3. For those, who haven’t checked it out before - the one-liner description of Silverlight.FX - "a lightweight framework for building well structured RIAs". A more detailed description can be found on the project page, as well as various blog posts from the past.

For those, who have checked it out before, or are using it, there haven’t been significant changes. Here are the notable ones (I’ve used snippets from the New York Times sample where applicable):

XApplication replaced with ApplicationContext
XApplication used to derive from the Silverlight Application base class, and provided functionality such as theming, windowing, an IoC container etc. This has been replaced with an ApplicationContext service to be placed in the new Application.ApplicationLifetimeObjects collection introduced in Silverlight 3. Blend doesn’t like derived Application types, and this takes care of that.

Before:

<fxapp:XApplication
  xmlns:fxapp="clr-namespace:SilverlightFX.Applications;assembly=SilverlightFX"
  xmlns:appsvc="clr-namespace:NewsWidget.Services"
  ...>
  <fxapp:XApplication.Components>
    <appsvc:TimesNewsWireService />
  </fxapp:XApplication.Components>
</fxapp:XApplication>

After:

<Application
  xmlns:fxapp="clr-namespace:SilverlightFX.Applications;assembly=SilverlightFX"
  xmlns:appsvc="clr-namespace:NewsWidget.Services"
  ...>
  <Application.ApplicationLifetimeObjects>
    <fxapp:ApplicationContext>
      <appsvc:TimesNewsWireService />
    </fxapp:ApplicationContext>
  </Application.ApplicationLifetimeObjects>
</Application>

Integration with Browser Back/Forward in PageFrame (Navigation)
The navigation feature in Silverlight.FX (PageFrame, Page etc.) supports URI-based navigation capability that supports both simple mapping of URIs to Page types that you'd expect, as well as supporting a MVC-based navigation model, where URIs map to actions on controllers (both sync and async), and action results are mapped to views and view models. PageFrame also supports cross-page transitions (like cross-fade, flip, slide etc.) in a declarative manner.

<fxnav:PageFrame x:Name="mainFrame"
  IsIntegratedWithBrowser="True">
  <fxnav:PageFrame.Loader>
    <fxnav:MvcPageLoader />
  </fxnav:PageFrame.Loader>
  <fxnav:PageFrame.Transition>
    <fxtransition:CrossFade Duration="00:00:0.25" />
  </fxnav:PageFrame.Transition>
</fxnav:PageFrame>

New Effects - Float and Spin3D
I couldn’t resist adding a couple of small new features that leverage some new capabilities of Silverlight 3. I’ve added the “Float” effect and the “Spin3D” effect. Note that effects in Silverlight.FX are behaviors that can be attached to elements and play an animation in response to various events. For example, the HoverEffect is a behavior that plays a forward animation upon mouse enter, and the inverse animation upon mouse leave (i.e. no need to deal with events, explicitly beginning/stopping storyboards, or defining storyboards for simple short-duration animations).

The Float effect simulates an object floating by projecting it forward along the z-axis, and by adding a drop-shadow behind it. The Spin3D effect rotates the element along one or more of the axes. Both of these effects use the new 3D plane projection and pixel effects under the covers. Here is some example markup:

<Border Background="#ED971F">
  <fxui:Interaction.Behaviors>
    <fxui:HoverEffect>
      <fxeffects:Float Distance="100" ShadowLength="10" />
    </fxui:HoverEffect>
    <fxui:ClickEffect>
      <fxeffects:Spin3D SpinAroundXAxis="True" SpinAroundYAxis="True" SpinAroundZAxis="True"
        Duration="00:00:02" />
    </fxui:ClickEffect>
  </fxui:Interaction.Behaviors>
</Border>

Check out Glitz2Page.xaml for a running sample.

Miscellaneous
There are a few renames in the underlying infrastructure – for example Effect was renamed to AnimationEffect, so you don’t see ambiguous names with the newly introduced Effects functionality in Silverlight 3. None of these changes should affect apps themselves that were using effects declaratively.

From the project page, you can download all the sources and binaries along with samples, both mini-experiments, as well as more end-to-end app scenarios.

If you’re using Silverlight.FX, please do drop a note. I’d love to get a sense of the cool things people are doing with the framework. Also, if you have suggestions for what you’d like to see, please include them as well.

Posted on Thursday, 7/16/2009 @ 11:37 PM | #Silverlight


Comments

24 comments have been posted.

Raghuraman

Posted on 7/17/2009 @ 3:21 AM
Thanks for the update.

Ricardo Fiel

Posted on 7/17/2009 @ 4:34 AM
Hi Nikhil,

Thanks for the update! I'll try it on our latest projects, along with the new stuff.
Here at Fullsix Portugal, your MouseWheelBehavior is essential in every project.

Cheers.

Brian Swiger

Posted on 7/17/2009 @ 6:02 AM
Thanks for the update! We'll be using this hopefully on a project I'm working for a client. Slick stuff. Thanks for the time and for sharing!

Ross

Posted on 7/17/2009 @ 9:41 AM
Hi Nikhil,

I'm trying to figure out how to do the Flip effect in Blend 3. I can drag out a ClickEffect, and put a Flip inside of it like this:

<Grid x:Name="flipContainer">
<Image Source="Images/Back.png" Width="400" Height="180" />
<Image Source="Images/Front.png" Width="400" Height="180" />
</Grid>
<fxui:ClickEffect>
<fxtransition:Flip Duration="00:00:01" TargetName="flipContainer"/>
</fxui:ClickEffect>

But this doesn't work. I have to surround the ClickEffect with <fxui:Interaction.Behaviors>. However, when I do that, the ClickEffect and Flip do not show up in the Blend object hierarchy.

Is there a way to add these effects via drag/drop in Blend 3?

Thanks,
Ross

Nikhil Kothari

Posted on 7/17/2009 @ 12:58 PM
@Ross,
You'll want a Button and the something like this (see the samples as well):
<Button>
<fxui:Interaction.Behaviors>
<!-- ClickEffect goes here -->
</fxui:Interaction.Behaviors>
</Button>

Scott Cate

Posted on 7/18/2009 @ 11:06 PM
For those of you looking for Glitz2Page.xaml (like I was), it's in the zip file. in the samples\experiments folder.

SilverlightFX.3.1.zip\SilverlightFX\samples\Experiments

http://cloud.github.com/downloads/NikhilK/silverlightfx/SilverlightFX.3.1.zip

John Billingsly

Posted on 7/20/2009 @ 4:02 PM
How does Silverlight.FX compare to Composite Application Guidance for WPF and Silverlight at http://www.codeplex.com/CompositeWPF, which support MVP and MV-VM patter for creating Silverlight applications.

Nikhil Kothari

Posted on 7/21/2009 @ 5:57 AM
@John -
Can you point to where Prism supports MVVM? - note when I ask that, I mean more than an implementation of ICommand.
My impression is Prism is focused on composite apps, which Silverlight.FX isn't focused on (yet).

mario

Posted on 7/26/2009 @ 8:36 AM
silverlightfx project page not working :( want to learn more. looking for a lightweight SL framework.

mario

Posted on 7/26/2009 @ 8:47 AM
silverlightfx project page not working :( want to learn more. looking for a lightweight SL framework.

Jack Addington

Posted on 7/26/2009 @ 12:13 PM
Nikhil,

Fairly easy to upgrade from 2.1 to 3.1 although I'm still playing around with the navigation a bit.

I noticed you addressed the Application issue for blend, any plan on addressing some of the other issues that restrict the use of Blend? So far I am seeing issues with TriggerAction -> The TypeConverter for "TriggerAction" does not support converting from a string for <fxui:EventTrigger EventName="Click" Action="$model.OpenProgramObjectExplorer($dataContext)"/>

Also picking up styles from the theme file.

I'm really looking forward to seeing your next sample

Thanks

jack

Nikhil Kothari

Posted on 7/26/2009 @ 9:07 PM
@Jack
Thanks for bringing up the TypeConverter issue. I will look into it.

As far as styles go, I am inclined to suggest using just merged resource dictionaries. The theme feature in Silverlight.FX will then basically be responsible for picking the right resource dictionary based on app parameters and merge it in into the application's resources.

Ken

Posted on 7/27/2009 @ 7:55 AM
John asked how Silverlight.FX compares to PRISM. How does Silverlight.FX compare to .NET RIA Services?

Jack Addington

Posted on 7/27/2009 @ 9:22 AM
I will look into the merged resource dictionaries - Just to clarify, So I use the merged resources in my application resources so that Blend can pick up my Theme.xml. If I actually had multiple themes then I would toggle what was in the list so Blend wouldn't end up with duplicates.

Any way to get around the issue of nested types not being supported "ModelType="Epm.Silverlight.Views.ProgramObject.ObjectInfoListViewModel" when I specify the model in XAML?

thanks

jack

Jack Addington

Posted on 7/27/2009 @ 9:40 AM
With respect to Navigation - I am having issues with the DefaultURI and throwing an error. If you change the News sample to use the debug version of the dll's then it happens as well. The pageFrame is unable to handle a defaultURI. I get an error on application startup, and then another error after navigating to the first 'page' as the Navigated event is trying to access the old page which is null. I believe I had emailed you earlier about it and then change I had to make.

Also, and I haven't looked too much, but is it possible to not show the full URI in the address bar? I don't really like having the displayed URL include all the keys etc that I am using in complex URI.

http://localhost:3168/Epm.aspx#/EpmNavigation/OpenObjectExplorer?programId=400&siteId=47&objectId=374873

1) is there a way to have this show up as something a little more user friendly?
2) if I actually cut/paste that and run it in a new IE window how do I get my page to navigate there directly? It just opens my app but doesn't do the initial navigation
3) If I navigate a couple of nested levels deep, and then hit back for each time I get a error once I get back to the first page as the 'Specified URL doesn't resolve to a Page'. I believe this relates to the 'first' instance of navigating to a default URI.

thanks

jack

Jack Addington

Posted on 7/27/2009 @ 12:50 PM
Something else I can't quite get to work - I'm trying to open a form by clicking on an image in the datatemplate of an ItemsControl. I couldn't do this in SL3 but with ElementBinding I thought it would work. I'm binding the FormModel to the DataContext.ModelProperty of the ItemsControl. The binding is somewhat working because as each row is created I can trap the GetModel accessor in my ViewModel. However when trigger actually fires it isn't re-getting the property.

Basically the difference is that when I put the same logic on a button outside the datacontrol the binding only everfires when the trigger is activated. When the trigger is in the ItemsControl dataTemplate it is firing the binding for each row as it is displayed the first time but then never called again.

I tried binding to the Model.GetFormModel property in lieu of DataContext.GetFormModel and using the actual page as the ElementName however that didn't ever call the GetFormModel so the form crashed /w a null Model object.

Not sure if this is an expected result, a limitation, or something that can be modified. I would have expected the same behavior that the binding doesn't fire until the trigger is 'triggered'. Below is a snippits from my XAML. The button works as expected ... t

<!--Manage MissingData button-->
<fxui:XButton x:Name="ManageMissingDataButton">
<fxui:HStackPanel ChildFlow="Left" ChildAlignment="Center" ChildSpacing="6">
<Image Source="/Epm.Silverlight;component/Themes/Icons/24/StatusFlagYellow24.png" />
<TextBlock Text="Manage Missing Data" Style="{StaticResource sectionTitleText}"/>
</fxui:HStackPanel>
<fxui:Interaction.Triggers>
<fxui:ClickTrigger>
<fxactions:ShowForm FormType="Epm.Silverlight.Views.DataEntry.MissingDataPopupForm" FormModel="{Binding MissingDataModel}"/>
</fxui:ClickTrigger>
</fxui:Interaction.Triggers>
</fxui:XButton>


<ItemsControl x:Name="DataFieldList" ItemsSource="{Binding CurrentDataFields}" BorderThickness="0" Opacity=".95">
<ItemsControl.ItemTemplate>
<DataTemplate>

...

<!--Missing Data Flag/Status-->
<Image Grid.Row="2" Grid.Column="7" Height="16" Width="16" VerticalAlignment="Top"
Source="{Binding Converter={StaticResource ConvertMissingDataStatus}, ConverterParameter='16', Mode=OneWay, Path=GuiFlagMissingData}">

<fxui:Interaction.Triggers>
<fxui:EventTrigger EventName="MouseLeftButtonUp">
<fxactions:ShowForm FormType="Epm.Silverlight.Views.DataEntry.MissingDataPopupForm"
FormModel="{Binding DataContext.MissingDataModel, ElementName=DataFieldList}"/>
</fxui:EventTrigger>
</fxui:Interaction.Triggers>

</Image>

</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

Jack Addington

Posted on 7/27/2009 @ 1:13 PM
Another issue with respect to the prior comment

I have Window|PageFrame + Flip Transition
Open Page
Open Form /w Binded FormModel from Page.Model (same Form as prior comment)
Form has a DetailView /w Slide transition
Close Form
RaisePropertyChanged on ItemsControl DataContext - triggers FormModel property on parent which updates the collection bound to the DetailView on the Form which triggers the transition

However something is confused in that it tries to fire the flip animation which I can only assume is coming from the pageFrame as that is the only place I have Flip. I get the following exception:

System.InvalidOperationException occurred
Message="A FlipEffect's target Panel must have 2 children."
StackTrace:
at System.Windows.Media.Glitz.Transition.CreateEffectAnimation(AnimationEffectDirection direction)
InnerException:


Now I can get rid of the problem by either destroying the formModel after the form closes or not trying to trigger the form in the Items Control. But it seems like the Form, although closed, is still trying to do its animation. For me it isn't noticeably to destroy my FormModel but in some cases I would think it might be useful???

Sorry for the length post.

jack

NaturalGenius

Posted on 7/29/2009 @ 5:46 AM
thanks so much nikhilk for Silverlight.FX
you are really appreciated here in Alliedsoft Nigeria.

How do you implement Silverlight FX with child window using MVVM

Namrata

Posted on 8/4/2009 @ 3:50 AM
good but i guess it contains many bugs.................and bit complicated also

tanmoy

Posted on 8/16/2009 @ 8:52 AM
Hi,
I can not find IsIntegratedWithBrowser property in PageFrame. Is there anything I am missing?

Yauhen Safrankou

Posted on 11/15/2009 @ 12:41 PM
Hi Nikhil,

You wrote "The navigation feature in Silverlight.FX (PageFrame, Page etc.) supports URI-based navigation capability that supports simple mapping of URIs to Page".

I cannot find a way how to do that in not mvc navigation application. How can I map an URI to a specific xaml Page?

In standard Silverlight 3 it is possible to use the UriMapper:
<nav:Frame ...>
<nav:Frame.UriMapper>
<urimapper:UriMapper>
<urimapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}View.xaml" />
</urimapper:UriMapper>
</nav:Frame.UriMapper>
</nav:Frame>
<navigation:Frame.UriMapper>

SilverlightFX's PageFrame does not have the UriMapper property. Do I miss something?

Thank you.

Yauhen Safrankou

Posted on 11/15/2009 @ 1:45 PM
Oh, I see now... I had to review the source code first before asking such questions...

Default PageLoader does it automatilally mapping all *Page pages. So, if we have "MySilverlightPage.xaml" it is being mapped to the "mysilverlight" address.

P.S. on another topic. could you add the Title property to the Page class? otherwise the browser history does not look nice. thanks =)

Arundhati

Posted on 11/19/2009 @ 10:47 AM
Hi,
I am using RadDragandDropManager with silverlight.FX (Trying to Drag and drop in Listview controls)... now for work around, I added code in code behind file to catch the events. When I get 'e.Options' from AddDragInfoHandler, I pass the selected value (Selected item) to my Model ... To get hold of Model I am using 'this.Model' in code behind (So that I can pass selected Item to the Model .. for other operations). The problem is, this.Model gives me cloned model. So when I change any property in the Model, it does not reflect in my View.
Is there a better way of using Silverlight.FX with RadDragandDropManager ?
Thanks ..

Neil Bostrom

Posted on 11/24/2009 @ 6:14 AM
Hi Nikhil,

I'm using your Silverlight.FX framework of power and loving it!

Small feature request, your default error handling in ApplicationContext has no way to be turned off! As I have my own handler, i didn't want your HtmlPage.Window.Eval("throw new Error('Unhandled Error: " + str + "');"); to keep getting reported. (As it doesn't seem to work that well in FF, unterminated string literal reported)

My error handler does HtmlPage.Window.Eval("throw \"Unhandled Error in Silverlight Application: " + errorMsg + "\";"); which seems much more FF friendly.

The only way I have found to stop your error handler is to inherit your ApplicationContext class and override OnError, which just feels a little excessive.
Post your comment and continue the discussion.