WebMasterSam

.Net, SEO, Dynamics CRM, AdSense/AdWords, Dating sites, Silverlight, Web hosting and more

About me

I'm an IT consultant working primarily with the .Net Framework as a developper and architect. I also work on my own on my personnal dating websites. I've been developping websites since 2000.

If you like what I do, feel free to support me

PayPal - The safer, easier way to pay online!

Bookmark

Bookmark and Share

Last comments

None

What is a .XAP file (SilverLight) and what does it contain

If you already created a Silverlight application you have certainly noticed that all you do in your Silverlight project will be packaged as a XAP file that you will then put on your website.

What is a XAP file ?

The XAP file is a package that contains everything your Silverlight application needs to run on the client browser.

What does it contain ?

All the assemblies (DLL) you created, all the Framework assemblies you referenced in your application (like System.Xml.Linq, System.Windows.Controls and some others) and a manifest file, named AppManifest.xaml. It also contains culture-specific assemblies (if you translated your application in some other languages).

What does XAP stands for ?

You have to pronounce "ZAP" and it stands for "Silverlight Application Package". I don't know why MS didn't called it SAP instead of XAP but... this is it's meaning !

Can I open a XAP file ?

Oh sure you can, it's only a ZIP file. You can rename it an open it with WinRar or WinZip.

How can I create a XAP file ?

You build your Silverlight project ! Simple, no ?

Why does my Silverlight application is packaged in a XAP file ?

There's 3 main reasons for this :

  1. Because all the content can be compressed within the zip file so you save bandwith and time
  2. Because DLLs are prohibited from downloading (by default)
  3. Because it's easier to download one file than "72" (any number) files
What does the AppManifest.xaml looks like ?

This file is the main entry point in the package for the Silverlight client. When Silverlight extracts the content of the XAP package it reads the AppManifest.xaml to know which assembly it has to load.


<Deployment EntryPointAssembly="SilverlightApplication1">
  <Deployment.Parts>
    <AssemblyPart x:Name="SilverlightApplication1" Source="SilverlightApplication1.dll" />
    <AssemblyPart x:Name="Silverlight.Trace" Source="Silverlight.Trace.dll" />
    <AssemblyPart x:Name="System.Windows.Controls" Source="System.Windows.Controls.dll" />
    <AssemblyPart x:Name="System.Xml.Linq" Source="System.Xml.Linq.dll" />
    <AssemblyPart Source="en/SilverlightApplication1.resources.dll" />
    <AssemblyPart Source="fr/SilverlightApplication1.resources.dll" />
    <AssemblyPart Source="fr/System.Xml.Linq.resources.dll" />
    <AssemblyPart Source="fr/System.Windows.Controls.resources.dll" />
  </Deployment.Parts>
</Deployment>

How do I use a XAP file ?

You ? You don't use this file; Silverlight does. The only thing you have to do with it is copy it to your ASP.Net application.

Where do I deploy my XAP file ?

If you want to do it the common way, deploy it to the ClientBin folder. You can deploy it wherever you want but, I suggest you put it in the ClientBin folder.

How to pass Culture and UI-Culture to Silverlight

Globalization is a common thing when you create websites that targets many different cultures (country and languages), so localizing your interfaces is a must.

If you already know how to pass parameters to a Silverlight application with the InitParams, you can think of passing your culture via those parameters and then set the culture at runtime. It will work, there's no doubt about it, but when a functionnality is supported by a specific technology, you must it the way it's used to be; not create a parallel functionnality.

So here's what you will have to add to you Silverlight HTML object code :


<param name="culture" value="fr-CA" /><param name="uiculture" value="fr-CA" />

It's easy and clean !

Posted: Apr 26 2009, 18:13 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | Programming | Silverlight
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Multiline TextBox in Silverlight 2.0

If, like me, you create some Silverlight applications, you probably said the same thing I said today : "Where the hell is the TextMode property of the TextBox ?!". In Silverlight it does not exist... so you can't set it to "Multiline" when you want a "TextArea" so you can type the Enter key so it adds a carriage return to the content of the TextBox.

The property's not completely gone... but the new property you get only gives you the chance to accept EnterKey or not; it's name is AcceptReturn. Use it like this :


<TextBox AcceptsReturn="True" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" />

Posted: Apr 25 2009, 14:42 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | Programming | Silverlight
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Easily pass parameters to Silverlight (and retrieve it everywhere in your app)

 

When you want to pass values (parameters) to a Silverlight application from within a web page, you can use the "initParams" fixed parameter. By default it does not contain anything. If you want to use it you must declare it this way :

You will notice that all the params must be passed within a single comma-separated string. Silverlight works this way. Because it works this way, you don't have to manually parse that string to get parameters and values, Silverlight parses it for you. If you want to retrieve a value of a parameter you passed, you can check on the dictionnary of parameters. The dictionnary is available on the StartupEventArgs of the Application_Startup event.

Because I wanted my parameters to be available everywhere and aasily parseable to the right type I created this simple helper class that wraps all the logic behind initParams.


    public class StartupParameters
    {
        #region Members

            private static IDictionary<string, string> _initParams = null;

        #endregion

        #region Methods

            public static void Initialize(IDictionary<string, string> initParams)
            {
                _initParams = initParams;
            }

            public static string GetParameter(string name)
            {
                if (ParameterExists(name))
                    return _initParams[name];
                else
                    return string.Empty;
            }

            public static bool GetParameterBoolean(string name)
            {
                bool blnResult = false;

                if (bool.TryParse(GetParameter(name), out blnResult))
                    return blnResult;
                else
                    return false;
            }

            public static int GetParameterInteger(string name)
            {
                int intResult = 0;

                if (int.TryParse(GetParameter(name), out intResult))
                    return intResult;
                else
                    return 0;
            }

            public static long GetParameterLong(string name)
            {
                long lngResult = 0;

                if (long.TryParse(GetParameter(name), out lngResult))
                    return lngResult;
                else
                    return 0;
            }

            public static bool ParameterExists(string nom)
            {
                return _initParams.ContainsKey(nom);
            }

        #endregion
    }

The only thing you have to do to properly use this class is to initialize it using the Initialize method receiving the initParams dictionnary, just like this :


     private void Application_Startup(object sender, StartupEventArgs e)
     {
           StartupParameters.Initialize(e.InitParams);

           this.RootVisual = new SilverlightControl1();
     }

Now you always have your parameters with you wherever you are in your Silverlight application.

Posted: Apr 25 2009, 14:03 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | Silverlight
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Silverlight trace; use this simple tracing class

For those who work with Silverlight already knows that Silverlight runs in a sandbox so your disconnected from all the local resources on the client-side, except something called IsolatedStorage. This is what I used to create my very own tracing class. It is only a small tracing class but it does all you want. Feel free to customize it if you need more functionnalities.


    public class Trace
    {
        private static IsolatedStorageFile _storageFile = null;
        private static IsolatedStorageFileStream _storageFileStream = null;
        private static StreamWriter _streamWriter = null;

        static Trace()
        {
            _storageFile = IsolatedStorageFile.GetUserStoreForApplication();
            _storageFileStream = _storageFile.OpenFile("Trace.log", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
            _streamWriter = new StreamWriter(_storageFileStream);
            _streamWriter.AutoFlush = true;
        }

        ~Trace()
        {
            _storageFileStream.Close();
        }

        public static void Write(String message)
        {
            _streamWriter.WriteLine(message);
        }
    }

Posted: Apr 21 2009, 14:46 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | Silverlight
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Asynchronous UI update in Silverlight; here comes the Dispatcher

For those who are familiar with multi-thread developpment already know that cross-thread calls are not allowed. Silverlight is no exception. When you have some code that will execute asynchronously, like an event handler or a timer tick, you will have to involve something called the "Dispatcher". The Dispatcher  is here to help you update the UI asynchronously.

You don't have to use it everytime you want to execute some asynchronous code; you only have to use this when you want to update the UI. The Dispatcher is very easy to use and understand. Because the Dispatcher can handle anonymous delegates, you can do something like this in all you event handlers :


Dispatcher.BeginInvoke(delegate()
{
    // Your UI updating code goes here
});

That's really simple, and it works well.

Posted: Apr 20 2009, 16:43 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | Silverlight
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Display a MessageBox in Silverlight

 

For people who tries to find the "MessageBox" class in Silverlight to display a message in a pop-up like we do in WinForms will have difficulty to find it because this doesn't work the same way. Because Silverlight runs in the browser, the message box is the one that is available in JavaScript: the "alert" method.


System.Windows.Browser.HtmlPage.Window.Alert("Your message goes here");

In the Window object (System.Windows.Browser.HtmlPage.Window) you will find some other things like "Prompt", "Navigate", "AttachEvent" and "Confirm". It shows how integrated with the browser and the JavaScript code Silverlight is, and this is a real good thing because you can easily make those 2 technologies talk together.

 

Posted: Apr 20 2009, 16:33 by WebMasterSam | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: .Net | JavaScript | Silverlight
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us
LINK BUILDING IS PROHIBITED ON THIS WEBSITE