Feed Icon  

Contact

  • Bryant Likes
  • Send mail to the author(s) E-mail
  • twitter
  • View Bryant Likes's profile on LinkedIn
  • del.icio.us
Get Microsoft Silverlight
by clicking "Install Microsoft Silverlight" you accept the
Silverlight license agreement

Hosting By

Hot Topics

Tags

Open Source Projects

Archives

Ads

Switching XAP Files on the Client Side

Posted in Silverlight at Monday, 22 December 2008 12:15 Pacific Standard Time

qingquan126778 asked the question in the Silverlight forums about how to switch between pages in Silverlight if the pages are in different xap files. First I pointed to Jesse Liberty’s post on multi-page applications (qinqquan wanted different xap files, not just pages) and then Mike Snow’s post on swapping between xap files using the ASP.NET server control (qingquan wanted client side only).

So since neither one was quite right, I coded up an example of my own that is based off Mike’s example but uses client side scripting instead of server side. Basically you grab a reference to the Silverlight plugin control via the onLoad event and then just set the Source property to the new xap.

function App2()
{
    slCtl.Source = "ClientBin/SilverlightApplication2.xap";
}

Download Source Here

BTW – Did you vote on my 10k Content Entry yet? :)

MIX 10k Challenge Entry

Posted in Silverlight at Monday, 22 December 2008 07:35 Pacific Standard Time

So my entry in the Mix 10K challenge is up in the gallery. It was a fun little project to create and I went well over 10k many times during the project and then had to whittle it back down each time. It is a feed reader that allows you to subscribe to feeds and it stores your subscriptions in Isolated Storage. I thought it was somewhat original, but then I watched this video on the contest and Adam even mentions an RSS reader, so I guess it was little obvious. :)

If you’re looking to enter the contest a few good posts on the subject are Adam’s post and Bill Reiss’ post.

Anyhow, check out my feed reader and be sure to vote!

Silverlight Dependency Properties

Posted in Silverlight at Monday, 15 December 2008 02:08 Pacific Standard Time

I’ve seen this question a number of times in the Silverlight Forums, so instead of just answering it one more time I decided to answer it here so I can refer back to this. The question generally looks like this:

I have create a dependency property and the setter isn’t getting called during data binding. My dependency property is declared as follows:

public class MyClass : Control

{

 

 

    public int MyProperty

    {

        get { return (int)GetValue(MyPropertyProperty); }

        set

        {

            SetValue(MyPropertyProperty, value);

            // some custom code here

        }

    }

 

    // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...

    public static readonly DependencyProperty MyPropertyProperty =

        DependencyProperty.Register("MyProperty", typeof(int), typeof(MyClass), new PropertyMetadata(0));

 

 

}

 

The reason why the setter isn’t called here (at least the way I understand this), is that when data binding sets this value it isn’t calling the public property. Instead it is using the SetValue on the dependency object instead. So the custom code is never called. What you need to do is add a PropertyChangedCallback to the DependencyProperty registration as follows:

public int MyProperty

{

    get { return (int)GetValue(MyPropertyProperty); }

    set

    {

        SetValue(MyPropertyProperty, value);

    }

}

 

// Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...

public static readonly DependencyProperty MyPropertyProperty =

    DependencyProperty.Register("MyProperty", typeof(int), typeof(MyClass), new PropertyMetadata(0, MyPropertyChanged));

 

private static void MyPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)

{

    ((MyClass)o).OnMyPropertyChanged((int)e.NewValue);

}

 

private void OnMyPropertyChanged(int newValue)

{

    // custom code goes here instead

}

 

 

Now whenever the property changes the OnMyPropertyChanged method will get called. Notice that this is where you put your custom code to handle the property changing. This code will get called when the public property setter is called or when the property is changed using the SetValue method.

More information on Dependency Properties can be found here.