Display Silverlight loading Interstitial without blocking design surface

My Silverlight application makes a lot of web service calls on the initialization of the view model. I don’t want the user touching things while it loads but I also want the user to be able to be visibly notified something is happening and to wait.

In comes a nice interstitial control/loading panel I wrote. The problem is, the control takes up the entire form and it needs to be the topmost control. What’s the problem? Well, can’t see the form or work on it when the loading panel is in my face.

The resolution was to create a Boolean to Opacity converter . The converter works great for making the Control appear and disappear and the use of the FallbackValue lets me work with it in design mode.

Resources definition for converter

<UserControl.Resources>
 <infrastructure:BooleanToVisibilityConverter x:Key="boolConverter"/>
 <infrastructure:BooleanToOpacityConverter x:Key="boolOpacityConverter"/>
 </UserControl.Resources>

Declaration of the control in the xaml

<my:LoadingInterstitial   x:Name="LoadingInterstitial1" Opacity="{Binding FallbackValue=0,Path=IsReady,Converter={StaticResource boolOpacityConverter}, ConverterParameter=True }" Visibility ="{Binding FallbackValue=Collapsed,Path=IsReady,Converter={StaticResource boolConverter}, ConverterParameter=True }"  />

Implementation of the value converter

using System;
using System.Windows;
using System.Globalization;
using System.Windows.Data;

namespace PwC.AuraOnline.Infrastructure.Converters
{
 public class BooleanToOpacityConverter : IValueConverter
 {
 /// <summary>
 /// Modifies the source data before passing it to the target for display in the UI.
 /// </summary>
 /// <param name="value">The source data being passed to the target.</param>
 /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the target dependency property.</param>
 /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
 /// <param name="culture">The culture of the conversion.</param>
 /// <returns>
 /// The value to be passed to the target dependency property.
 /// </returns>
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
 var flag = false;
 if (value is bool)
 {
 flag = (bool)value;
 }
 else if (value is bool?)
 {
 var nullable = (bool?)value;
 flag = nullable.GetValueOrDefault();
 }
 if (parameter != null)
 {
 if (bool.Parse((string)parameter))
 {
 flag = !flag;
 }
 }
 if (flag)
 {
 return 100;
 }
 else
 {
 return 0;
 }
 }

 /// <summary>
 /// Modifies the target data before passing it to the source object.  This method is called only in <see cref="F:System.Windows.Data.BindingMode.TwoWay"/> bindings.
 /// </summary>
 /// <param name="value">The target data being passed to the source.</param>
 /// <param name="targetType">The <see cref="T:System.Type"/> of data expected by the source object.</param>
 /// <param name="parameter">An optional parameter to be used in the converter logic.</param>
 /// <param name="culture">The culture of the conversion.</param>
 /// <returns>
 /// The value to be passed to the source object.
 /// </returns>
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
 var back = value.GetHashCode() == 100;
 if (parameter != null)
 {
 if ((bool)parameter)
 {
 back = !back;
 }
 }
 return back;
 }
 }
}

The above code will help you on your way.

If you haven’t used converters or are really new to Silverlight, I suggest reading a lot of the helpful materials out on the web.
If you are experienced, this is really easy to implement.

Happy Coding!

Bit by Telerik. Redirect’s in my Ajax Panel not working with .NET 4 upgrade

I upgraded my project with the latest Telerik Q1 2010 assemblies and went to .NET 4.0 at the same time. Well, almost all of my pages that would issue a redirect after they completed their work started failing.

I spent over a day trying to figure out the source. I watched Firebug showing the server responding with gibberish on all the redirects. The symptom was unintelligible response that the page didn’t seem to even be phased by.

Well, I started to think why the hell was I getting binary data streamed back? Should have been a simple redirect header. It finally dawned on me, I loaded the Telerik compression module a while back to try and speed up page delivery from their psychotically bloated pages.

I pulled out the compression modules and Voila! It all started working as it should. What a pile of crap that was!

Anyway, I hope this helps someone else out their pulling their hair. No searches of mine found anything even remotely useful.

<httpModules>
<!--<add name="RadCompression" type="Telerik.Web.UI.RadCompression" />-->
</httpModules>

Happy coding!