Errr, some catchy title.... RSS 2.0
 Thursday, June 28, 2007

So, you wrote your first RIA and you want to publish in on the web and start counting those millions of dollars coming in. You deploy your application, type in the link but, nothing happens. Why?

 

 

 

It could be, that your hosting service doesn’t support .xaml files (mine started around a month age). There is a quick workaround for that, simply rename your .xaml files to .xml. You have to update your references accordingly, such as when you create your xaml object via JavaScript. Luckily, if you do that, everything still works (Intellisense) inside Visual Studio so if you do this before deployment, you won’t have any problems.

 

Note: You don’t have to do this for User Controls as they are compiled into the binary file.

 

Let’s assume that you have created your Silverlight project that consists of one Page.xaml file some User Controls, one Default.html page (so typical set up in Visual Studio). Below is a list of files that need to be uploaded to the server:

 

Default.html

Default.html.js

Page.xaml (or Page.xml)

Silverlight.js

 

And the most important one:

ClientBin (the directory in which is the client DLL)

Thursday, June 28, 2007 10:16:01 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight
 Monday, June 11, 2007

I was writing a short project for myself in Silverlight that involved calling my own web service. Everything was working great in localhost, however when I uploaded it to my website, the application crashed and I had no idea why. After some time spent debugging (not the most pleasant thing in Silverlight I found out, that calling a web service from generated an exception:

 

Request format is unrecognized for URL unexpectedly ending in /MyMethod.

 

After looking at the problem, I realized that HTTP GET and HTTP POST Are Disabled by Default starting from ASP .NET 2.0. A quick fix has solved the problem, paste the following in the web.config and you’re good to go.

 

<system.web>

    <webServices>

        <protocols>

            <add name="HttpGet"/>

            <add name="HttpPost"/>

        </protocols>

    </webServices>

Monday, June 11, 2007 12:55:07 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight
 Friday, May 04, 2007

There are examples how to set image to the Image object in Silverlight (both in 1.0 and 1.1); however I haven’t found one how to set it to any object that can be filled. The beauty of XAML based applications is that you can put whatever media you want inside objects, so if you want to fill in Ellipse or a Path with an image you can. The easiest way to do it is just declaratively, in XAML:

 

<Rectangle x:Name="mainPic" Width="448" Height="386" Canvas.Left="288">

      <Rectangle.Fill>

            <ImageBrush ImageSource="pic.jpg" />

      </Rectangle.Fill>

</Rectangle>

 

 

This is great for static content, but what if you want to set it programmatically using Downloader object.

 

Below is the solution for 1.0 (I tested in on Feb CTP release)

 

var wpfe;

 

function root_Loaded(sender, args) {

      wpfe = document.getElementById("wpfeControl1");

     

      mainDownloader = wpfe.createObject("Downloader");

      mainDownloader.completed = "javascript:mainDownloadCompleted";

      mainDownloader.DownloadProgressChanged = "javascript:mainDownloadProgressChanged";

     

      mainDownloader.open("GET", "SomePic.JPG", true);

      mainDownloader.send();

     

}    

 

function mainDownloadCompleted(sender, args) {

    sender.findName("mainPic").Fill.ImageSource = sender.Uri;

}

 

 

Apart from setting the downloader, the most important code line is this:

 

    sender.findName("mainPic").Fill.ImageSource = sender.Uri;

 

When the image gets downloaded we set the Rectangle’s ImageBrush to its URL.

 

Now solution for 1.1 in C#:

 

public void Page_Loaded(object o, EventArgs e)

        {

            // Required to initialize variables

            InitializeComponent();

 

            Downloader downloader = new Downloader();

            downloader.Completed += new EventHandler(downloader_Completed);

            downloader.Open("GET", new Uri("SomePic.JPG", UriKind.Relative), true);

            downloader.Send();

        }

 

 

void downloader_Completed(object sender, EventArgs e)

        {

           (mainPic.Fill as ImageBrush).ImageSource = (sender as Downloader).Uri;

        }

 

Once again, the most important code line is this

 

(mainPic.Fill as ImageBrush).ImageSource = (sender as Downloader).Uri;

 

Notice, how much casting we have to do, because C #is a strongly typed language.

 

Hope this helps.

Friday, May 04, 2007 3:15:45 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Silverlight

This is a quick post describing my first impressions with Silverlight 1.1 and Orcas Beta 1.

 

Orcas:

·        Overall: a step forward in a good direction. I really enjoy working with it. Can’t wait for Resharper to come out for it J.

·        I love that I can finally debug JavaScript.

·        Nice and clean separation: When you have Page.html, you also get Paga.html.js. Now, we have code behind for everythingJ.

·        XAML explorer is a lot faster when I compare it to VS 2005.

·        Running Silverlight application launches default browser in the system (in my case Opera). There is no plugin for Opera to make Silverlight working, so I always get the lovely image Get Silverlight. I had to set IE to be my default browser. In VS 2005 IE launched always no matter what was the default browser, I preferred it that way.

·        Ctrl + Right Arrow (and Ctrl + Left Arrow) don’t work! When I checked keyboard shortcuts in 2005 and Orcas they said exactly the same thing: Edit.MoveControlRight. Apparently this doesn’t work in Orcas on my machine. BTW: I had no idea how much I use this feature until it stopped working.

 

 

 

Silverlight:

  • Between 1.0 and 1.1 a HUGE step forward. I mean CLR on MAC, DLR and so on. My head still hurts….
  • It’s amazing I can write C# in my client app. I’ve written an Image Gallery for Silverlight 1.0 (actually when I wrote it, it was still WPF/E) and it wasn’t a joy ride. I didn’t enjoy debugging JavaScript with alert.
  • I’m rewriting it now to learn 1.1 and I’ve noticed that productivity boost is amazing. I truly believe that it will be possible to write simply amazing Rich Internet Applications with this technology.

 

 

Small Tip when building Silverlight applications with Orcas:

 

When you’re adding objects to XAML code that you want to reference in the code behind, make sure you use prefix x before Name property:

 

<Rectangle x:Name="mainPic" Width="448" Height="386" />

 

x of course corresponds to

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

Without that little x you will get compilation errors. It is a little bit counter intuitive since when you press n you also get a property Name, but this Name corresponds to the default schema

 

 

 

Friday, May 04, 2007 2:41:01 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
Orcas | Silverlight
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Marcin Waligora
Sign In
All Content © 2008, Marcin Waligora
DasBlog theme 'Business' created by Christoph De Baene (delarou)