Debug SL3 OOB application startup

May 27, 2009

Just a short post.
The other day I was having some trouble debugging the start up of a Silverlight 3 OOB application. The problem was well and truly gone before I could attach to the application from Visual Studio.

If you didn’t realise, you can attach VS to your OOB app by attaching to the appropriate sllauncher.exe instance.

As stated though, you will miss out on any start up problems you are trying to debug.

My (hacky) work around was to wack this in my start up code… I wacked it in MainPage.xaml.cs, but I can’t see any reason this won’t work in App.xaml.cs:

while (!Debugger.IsAttached)
{
    Thread.Sleep(100);
}

This code will basically hang the app until you attach your debugger! Just make sure you don’t let this one in to production :)


June 2 SDDN Meeting in Sydney

May 27, 2009

Miguel has been very organised and has another SDDN meeting off the ground in Sydney!

From Miguel’s blog:

“Next Tuesday, June 2 at 6:30 at Microsoft in Sydney (1 Epping Road, North Ryde NSW) we will have the SSDN Sydney’s June Meeting. This time Tatham Oddie will be talking about the new Out of Browser features in Silverlight 3 and Sergey Klementiev will presenting “LOB applications in Silverlight Lap around middle tier”. You will also have the opportunity to win a copy full of Expression 2 Suite and the best of all network amongst your Silverlight peers. So don’t miss it.”

Register on the site.

See you there!


First Virtual Silverlight Designer and Developer Network Meeting

May 14, 2009

Miguel has been hard at work organising our first ever virtual SDDN meeting!

It’s on May 18, 2009 at 9:00 pm Sydney Time.

See Miguel’s Blog for more details!

Link to the meeting will be released today hopefully.


Silverlight Slider that snaps to rounded value when dragged

May 10, 2009

The other day I had a problem where a slider had five distinct values and the user would drag the slider to their selection. An example of this would be a question like “From 1 to 5, please select how much you like puppies”. Of course, everyone would answer 5 to that question but that’s not the point… When a user clicked the slider (as opposed to dragging the thumb), the slider change would work fine, and the slider would go to the right place. The problem was that when the dragged the slider to change the value they could drag it to an intermediary value. Small change was 1 and large change was 1, but the could select 1.1393938… which would leave the slider sitting in a position between 1 and 2 somewhere.

The answer was to jump in to Silverlight Spy and have a bit of a hunt around the Slider code. I pulled out some of the code and created a new class inherited from Slider, and now when I drag it snaps to the right positions!

The code here is not complete, it doesn’t properly support IsDirectionReversed or Vertical sliders, but you could quite easily fix it for your own purposes.

Basically, just create a new control and inherit from Slider, then override the method as below.

Keep in mind, this to me is a fairly hacky approach :)

public class MySlider : Slider
    {
        protected override void OnValueChanged(double oldValue, double newValue)
        {
            int val = Convert.ToInt32(Math.Round(newValue));        

            Thumb ElementHorizontalThumb = GetTemplateChild("HorizontalThumb") as Thumb;

            double maximum = base.Maximum;
            double minimum = base.Minimum;

            double num3 = val;
            double num4 = 1.0 - ((maximum - num3) / (maximum - minimum));

            RepeatButton ElementHorizontalLargeDecrease = GetTemplateChild("HorizontalTrackLargeChangeDecreaseRepeatButton") as RepeatButton;
            RepeatButton ElementHorizontalLargeIncrease = GetTemplateChild("HorizontalTrackLargeChangeIncreaseRepeatButton") as RepeatButton;

            Grid grid = GetTemplateChild("HorizontalTemplate") as Grid;

            if (grid != null)
            {

                if ((grid.ColumnDefinitions != null) && (grid.ColumnDefinitions.Count == 3))
                {
                    grid.ColumnDefinitions[0].Width = new GridLength(1.0, GridUnitType.Auto);
                    grid.ColumnDefinitions[2].Width = new GridLength(1.0, GridUnitType.Star);

                    if (ElementHorizontalLargeDecrease != null)
                    {
                        ElementHorizontalLargeDecrease.SetValue(Grid.ColumnProperty, 0);
                    }
                    if (ElementHorizontalLargeIncrease != null)
                    {
                        ElementHorizontalLargeIncrease.SetValue(Grid.ColumnProperty, 2);
                    }
                }
                if ((ElementHorizontalLargeDecrease != null) && (ElementHorizontalThumb != null))
                {
                    ElementHorizontalLargeDecrease.Width = Math.Max(0.0, num4 * (base.ActualWidth - ElementHorizontalThumb.ActualWidth));
                }
            }
        }

    }

The main crux of this is that I first round the value, then pass it in as “num3″ which is then used to calculate the real position of the thumb slider.

As I said, a bit hacky, but it works nice!

I checked the Slider for a property that might turn it in to this mode, but couldn’t see anything… I think it would be a nice addition to the in built slider control.


REMIX09 Australia session list and speakers

May 2, 2009

The speaker and session lists for REMIX09 have been posted. Check out the speakers here and the session list (and registration link) here.

My session, the “Silverlight 3 Super Session” is first up, so come along and check it out!

REMIX09 is on June 11 at Star City in Sydney.