Search
Archives
Corey Miller
Twitter
Friday
Aug132010

Debugging Silverlight in Firefox

Just a little tip I learned recently but if you are an avid firefox user and you want to debug Silverlight 4 applications in the firefox browser, then here are a few steps you need to take to make that happen, since it doesn't work right out of the gate.

Step 1
In firefox, at the address bar type "about:config" without the quotes. If done correctly you will see a little warning.

Step 2
Accept the warning. Tell it you will be careful, you promise.

Step 3
In the filter field, type "dom.ipc.plugins.enabled.npctrl.dll" and you should see only 1 entry.

Step 4
Change the value from "true" to "false". You can do this by just double-clicking the entry.

Step 5
Restart the browser and you should be good to go.

Of course you could ignore all that and manually attach the visual studio debugger to "plugin-container.exe" but that would be painful and the above way is much easier.

Thursday
Aug052010

Talk - XAML: Things you should know

I gave my "XAML: Things you should know" talk at Chicago's Silverlight User Group last night. For those who missed it, I will be giving the same talk at CNUG: Chicago .Net User Group on August 18th. You can find out more here.

The talk focuses on subjects that are usually overlooked on your typical Silverlight or WPF presentations. I will focus on all things XAML. Specifically, I will be talking about Layout, Animation, Visual States, and Styling. So, if you are in Chicago, check it out.

As promised I uploaded the demo samples: XamlDemo.zip (570 KB)

Sunday
Apr252010

Silverlight 4 Getting Started

Silverlight 4 has officially been released for just a little over 10 days now and I thought it was appropriate to give you some details on how to get started with it. There are a few important things to understand before working with Silverlight 4. First check Tim Heuer's blog post on what is new in Silverlight 4 here.

Visual Studio 2010
First, Silverlight 4 development is only compatable with Visual Studio 2010 and NOT 2008. Therefore, if you have not yet gotten Visual Studio 2010, then I suggest using the express editions found here. (DONT WORRY! Visual Studio 2010 will install and work side by side with Visual Studio 2008)

Silverlight Tools for VS2010
Once you have Visual Studio 2010 in place, then you can get the Visual Studio 2010 tools, because VS 2010 ships only supporting Silverlight 3 out of the gate. Now this is where some confusion can set in. The tools, unlike the actual Silverlight 4 runtime have not been officially released. Thats right, the tools are only in "release canidate" mode and Microsoft promises to release these tools to official "RTM" soon but I don't know the date for them. You can get the tools here.

Silverlight Toolkit
Silverlight toolkit has been updated to an April release specifically to support Silverlight 4 and you can get those bits here.

Expression Blend 4
Like the VS2010 tools, Expression Blend 4 is also only in "RC" status and has not officially released yet. One great thing about Expression Blend 4 is if you currently own the full version of Expression Blend 3, you can upgrade to 4 at no additional cost. WOOHOO! You can download a trial of Expression Blend 4 RC here.

Silverlight 4 Training Kit
Microsoft has just released a new free Silverlight 4 Training Kit that walks you through building business applications with Silverlight 4. You can also download the entire offline version of the kit here.  You can use the 8 modules, 25 videos, and several hands on labs online or offline from links on the Channel 9 site.

Tuesday
Dec082009

Careful using Mouse.OverrideCursor

So I typically do not blog much about WPF but recently I have been doing so much work in WPF I only thought it fair to share my experiences with it. Today I found out a little problem when I noticed that my Cursors defined in XAML was not working. In my little test application it was working fine, but when I applied the code to my solution they weren't working. After some research eventually I had an "AH HA!" moment. In code, a typical windows developer likes to add "Cursors.Wait" when doing calls to various services. And I noticed the code looked liked this:

Mouse.OverrideCursor = Cursors.Wait;
//random synch process stuff
Mouse.OverrideCursor = Cursors.Arrow;

The problem wasn't obvious here, but once the wait cursor is done with its task the mistake is setting the "Cursors.Arrow". The default value of "OverrideCursor" is actually null, not arrow. By forcing it to arrow means no other call can update the cursor but another Mouse.OverrideCursor. So to correct the issue your code should look like this:

Mouse.OverrideCursor = Cursors.Wait;

//random synch process stuff

Mouse.OverrideCursor = null;

Monday
Dec072009

Creating an Image from PixelShaders in Silverlight and WPF

While this is not the best way to do image calculations in the code behind in terms of imaging with Silverlight and WPF I was perplexed with the problem of having a great pixel shader that I could apply in the xaml using Bitmap Effects but unclear as the best way to translate that to an actual Bitmap Image. If you are looking for a quick fix solution I wanted to share a little gold nugget in how to actually do this that I found. Just to explain a bit more this assumes you already know how to use Pixel Shaders, I will include a sample code to help illustrate this if you do not. But honestly that is a separate topic. I wish I had the source of this little nugget, it took alot of searching and improvising but eventually I came up with the following code:

In the XAML

<Image x:Name="OriginalImage" Source="img.jpg">

   <Image.Effect>

      <l:BrightContrastEffect  x:Name="MyEffect"

                    Brightness="{Binding ElementName=bVal, Path=Value}"

                    Contrast="{Binding ElementName=cVal, Path=Value}"/>

  </Image.Effect>

</Image>

In the Code

//using System.Windows.Media.Imaging;

//using System.Windows.Shapes;

//using System.Windows

//using System.Windows.Media;

BitmapSource bitmap = OriginalImage.Source as BitmapSource; //source from XAML

Size sz = new Size(bitmap.PixelWidth, bitmap.PixelHeight);

 

Rectangle r = new Rectangle();

r.Fill = new ImageBrush(bitmap);

r.Effect = MyEffect; //name applied in XAML

r.Measure(sz);

r.Arrange(new Rect(sz));

 

var rtb = new RenderTargetBitmap(

                    bitmap.PixelWidth, bitmap.PixelHeight, 

                    bitmap.Dpi, bitmap.DpiY, PixelFormats.Pbgra32);

rtb.Render(r);

What it essentially does is takes the effect you apply in the XAML and in the back end you can use that effect to create a new bitmap. You do this by virtually constructing a rectangle of the appropriate size and shape of the original image and applying the effect and the image to the rectangle and then saving that out using RenderTargetBitmap. I will upload a sample solution when I get home this afternoon.