Quantcast
Channel: dotMorten - Silverlight
Viewing all articles
Browse latest Browse all 23

WinRT vs. Silverlight - Part 5 - Defining default style template

$
0
0

See intro blogpost here.

Here's something that's actually NOT different in Silverlight (but it's different from WPF as it has always been).
You declare your style using DefaultStyleKey. This means the code looks like this for Silverlight, WPF and Windows Runtime:

publicclass MyControl : Control
{public MyControl()
    {#if SILVERLIGHT || NETFX_COREthis.DefaultStyleKey = typeof(MyControl);#endif
    }static MyControl() {#if !SILVERLIGHT && !NETFX_CORE
        DefaultStyleKeyProperty.OverrideMetadata(typeof(HoverControl),new FrameworkPropertyMetadata(typeof(HoverControl))); #endif
    }
}

Here is what IS different though: You need to set the build action of \Themes\Generic.xaml to "Content". It won't work without it.
Also note that when you add Generic.xaml to your project, it will also get added to App.Xaml. I assume this is a bug in the current release, but you will have to go and delete this entry, or it won't work.


Viewing all articles
Browse latest Browse all 23