Archives

Archives / 2009 / August
  • Silverlight Tour Paris in September

    silverlight_paris

    Paris The Silverlight Tour is coming one more time to Paris, France with real Silverlight 3 content inside ;-)

  • When: September 02-04
  • Where: Paris, France
  • Registration (Fr): http://www.octo.com/com/com_formation-silverlight.html

    If you are looking for 3 days of intensive Silverlight training in French this is your chance to learn it from soup to nuts!


  • For other cities/dates please consult:
    http://www.runatserver.com/SilverlightTraining.aspx


    Silverlight Tour on Facebook

     

    Technorati Tags:
  • Silverlight EnableFramerateCounter parameter

    EnableFramerateCounter is a parameter you can activate on the Silverlight Plug-in object. (For a comprehensive list of Silverlight param, see my previous post).

    This boolean value indicates whether to display in the hosting browser's status bar the current Silverlight frame rate per second (fps).

    <object type="application/x-silverlight-2">
      <param name="source" value="/ClientBin/FunWithFPS.xap"/>
      <param name="enableFramerateCounter" value="True" />
    </object>

    It is shown in the left side of the status bar as: fps:currentFramerate/maxFramerate

    EnableFramerateCounter in IE

    Note that maxframerate defaults to 60 so Silverlight try to display at 60 fps by default. You can change the maxframerate in the param list as well.

     

    So the EnableFramerateCounter setting can be useful during development to detect performance bottlenecks in your application.

    But… this works only in IE and on Microsoft Windows. Setting this value has no effect in other platforms.

    Also it appears that the default security level in IE prevent script from displaying information in status bar anymore, so you need to tweek this:

    In IE go to Tools / Internet Options / Security tab, then click on “Custom level…” and choose Enable for “Allow status bar updates via script” in the Scripting section.

     IE settings for EnableFramerateCounter

     

    Technorati Tags:
  • Provide startup parameters to Silverlight with InitParams

    I have been giving Silverlight trainings for a while now, and I found this to be a little known feature: the ability to provide Silverlight startup parameters with InitParams.

     

    Pass startup parameters to your Silverlight app

    You pass the parameters as a key/value pair collection in the initParams param of the object tag. (For a comprehensive list of param you can set, see my previous post).

    <object data="data:application/x-silverlight," type="application/x-silverlight-2" width="100%" height="100%">
        <param name="source" value="ClientBin/InitParamsSample.xap"/>
        <param name="onerror" value="onSilverlightError" />
        <param name="background" value="white" />
        <param name="initParams" value="module=news,nb=10" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">
            <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
        </a>
    </object>

     

    Get the parameters in Silverlight

    You get the startup parameters in the Application_Startup() event handler of the App class:

    App.xaml.cs

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        foreach (var item in e.InitParams)
        {
            this.Resources.Add(item.Key, item.Value);
        }
    
        this.RootVisual = new MainPage();
    }

    If you store them as Resources, then you can use them in any page like that:

    MainPage.xaml.cs

    public partial class MainPage : UserControl
    {
        string module = string.Empty;
        int nb = 0;
    
        public MainPage()
        {
            InitializeComponent();
    
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
    
        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (App.Current.Resources.Contains("module"))
            {
                module = App.Current.Resources["module"].ToString();
            }
            if (App.Current.Resources.Contains("nb"))
            {
                int.TryParse(App.Current.Resources["nb"].ToString(), out nb);
            }
    
            // Display the nb latest items from the selected module...
        }
    }

     

    Alternative option

    Or even better with a constructor in your xaml page:

    App.xaml.cs

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        if (e.InitParams.Keys.Contains("module"))
        {
            module = e.InitParams.Keys["module"].ToString();
        }
        if (e.InitParams.Keys.Contains("nb"))
        {
            int.TryParse(e.InitParams.Keys["nb"].ToString(), out nb);
        }
    
        this.RootVisual = new MainPage(module, nb);
    }

     

    MainPage.xaml.cs

    public partial class MainPage : UserControl
    {
        public MainPage(string initModule, int initNb)
        {
            InitializeComponent();
    
            // Display the nb latest items from the selected module...
        }
    }


    Download Sample project

     

    Technorati Tags:
  • [Cool tool] Silverlight Spy

    Silverlight Spy is a free(*) tool that allows you to inspect any online Silverlight app.

    Just launch it and point to a web page with a Silverlight app, then you can:

    • Explore the XAP package
    • Isolated Storage use
    • Monitor performance
    • Browse the UI visual and logical tree
    • Examine objects

    Here is a screen shot of the app that shows the UI inspection (Live XAML outline):

    You can even decompile code inside the dll, for that you need Reflector installed, then go to Tools / Options to configure it:

    It also comes with a tool to check Cross Domain policy files:

    This pane shows some info and interesting warnings:

    Try Silverlight Spy

    You can install it online via ClickOnce:

    http://silverlightspy.com/silverlightspy/download-silverlight-spy/

     

    (*) Silverlight Spy now has a version 3 which won’t be free as soon as it leaves beta mode.
    As seen on the website: ”Silverlight Spy 2 is no longer maintained and will be phased out eventually.”