Generic.xaml in Silverlight Beta1 for WPF developers

I woke up early this morning and decided to play around with Silverlight…. I love Silverlight it makes me feel like I am developing in WPF yet Cross Browser and Cross Platform…. can it get better than that???

Yet, this morning I had to swear a bit !

Generic.xaml xmlns

I was building a Silverlight custom control (as usual that the first thing I try out in a new platform 😀 ) and I found a post that helped me a lot. The first problem that I found was Visual Studio does not have a template for a ResourceDictionary for Silverlight.

As you all know in order to build a custom control Generic.Xaml is one of the most important things to do. Generic.Xaml would contain the UI of the custom controls.

Yet thanks to the post I just mentioned I got through this by create a Text File (naming it generic.xaml) and setting the Build Action to Resource. You must also clear all other fields… something like this

I said ok, I have the generic.xaml all set up now all I need to do is to create a Style for the control that will act as the UI for my new Custom control. First thing I did was to create an xmlns declaration so that I can style my control. something like this


As you can see I did not add the assembly part in this because I said since the generic.xaml is in the same project of the control class I would not need it. At least that is what you would do if you are a WPF developer. But guess what I ran the application and BAMMMM!!! I got a AG_E_UNKNOWN_ERROR. This is a nice error to get in 7 o clock in the morning 🙂

I started looking around to try and translate this error and I found a very helpful post. Yet still, I could not find the source of the problem… Then I tried something out, just to say that I tried it… basically I added the assembly part in my generic.xaml xmlns declaration… something like this


And Guess what… It worked!!!

For me this is quite crazy because I never had to do such a thing in WPF. Actually if you try to do that in WPF you would start getting an error because the generic.xaml is in the same assembly of the control you are trying to reference. But anyway, Silverlight is still BETA and I am more than sure that this will be fixed in the near future.

The ResourceDictionary.MergedDictionaries

Ok so with the xmlns problem fixed, I was hoping to find no other surprise but after a minute I got another one!!!

Usually when one is building a controls library you would create a ResourceDictionary for each control so that the generic.xaml would not get cluttered. And then you merge all dictionaries in the generic.xaml by using the ResourceDictionary.MergedDictionaries something like this…

   <ResourceDictionary Source="/AvalonControlsLibrary;component/Themes/Brushes.xaml"/>
   <ResourceDictionary Source="/AvalonControlsLibrary;component/Themes/DatePicker.xaml"/>

But guess what. There is no such thing YET in silverlight 😦
so you have to put all the resources for the controls in the generic.xaml. I didn’t find a workaround for this yet but I will update this post if/when I do.

Last word

Silverlight is really cool. Don’t let small things like this get in the way. I am more than sure that issues like this will be fixed in the near future…. I remember when WPF was still in Beta there where similar things. The only difference with Silverlight is that there is already WPF and people expect that Silverlight has the same capabilities. Eventually this will happen but for now we must wait 😀

Last 2 words – Silverlight Rocks!

kick it on

11 thoughts on “Generic.xaml in Silverlight Beta1 for WPF developers

  1. Nice!

    I’m working on my first SL application and article this week and will post on CP.

    This is great information.



  2. WPF/C#/Agile/Domain Driven Design in NYC

    Rich Altamura 201-638-9919

    I know you must get a lot of recruiters contacting you via your Blog for Jobs in WPF/Silverlight but thought this was a very special situation.

    My name is Rich Altamura and I am a specialist in recruitment of advanced Microsoft technologists. I thought you might be able to pass this opportunity around to your network.

    Very senior level role in WPF to build state of the art Algorithmic Trading System from scratch in WPF/C# focused on UI/Agile/Best Practices/TDD/Domain Driven Design.

    Need someone familiar with Juval Lowy, GoF, Kent Beck, Adam Nathan, etc. True hobbyist types.

    If you can help it will be much appreciated….If I can ever help you out please don’t hesitate to contact me.

    (C#/Agile/Domain Driven Design)-

    We are looking for an exceptional software engineer with demonstrated leadership and management skills to build a team and design and architect this product.

    This product will be built in all .NET specifically with C#/WPF technologies. The ability to lead, mentor a staff, and be extremely hands-on while maintaining adherence to a strategic vision using best practices is essential.

    The right candidate must have excellent real world C#, Winforms, and general User Interface experience.

    This is a tremendous opportunity for a talented C#/Winforms developer to leverage their deep Winforms/UI experience into the latest .Net technology.

    This is a brilliant team comprised of the top .Net talent in the industry. They welcome any brilliant developers who work in any industry who are absolutely passionate and creative about their trade. This team is constantly pushing the enveloper, doing research, reading books, attending conferences, etc.
    The use of AGILE methodology coupled with TDD/Nunit is paramount in the development. Strong methodology experience and the ability to contribute to the core architecture design from White Board concepts to production and delivery is key.

  3. Pingback: Mike Taulty's Blog : Silverlight, Custom Controls, Generic.xaml, Dictionaries, Errors

  4. Pingback: Silverlight Cream for March 21, 2008 - 2 -- #231

  5. This allows you to both make and receive calls as well.
    Unlike other wireless networked music players, the Eos wireless speaker system requires
    no software or Wi – Fi connection. Because of this, they developed and manufactured the
    Xbox 360 system that has everything you need in a gaming box

  6. This will increase the number of customers seeking research
    paper writing services from the firm. We can save you t from the trap of writing an admissions
    essay that will harm your chances. The aim of creative essay writing should
    be to convey a given idea or message in a creative manner.

    Use note cards to record notes from each source you have utilized while
    writing a research paper. Writing a research paper
    is a science. Many companies are currently offering students with online academic writing services.
    Unfortunately, not all writing agencies deliver content that
    would get you good grades. With the growth of China and India, coupled with the strong influx of foreign talent in Singapore, it is
    getting increasingly competitive to secure a good job in Singapore.
    Moreover, most public schools have recorded excellent job in educating their students and parents averagely
    pay lower tuition fee as compared to their counterparts. Firstly, we have classified
    databases depending on their storage purpose and capabilities. Thank you

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s