views:

125

answers:

2

I have a Xaml file which is used in a project which can be built for both Silverlight and WPF. I want to use the GridSplitter control. However, this control is in different Xaml namespaces on Silverlight and desktop WPF.

In WPF, the namespace is: http://schemas.microsoft.com/winfx/2006/xaml/presentation On Silverlight, it is: http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk

So if the xaml code is <GridSplitter/>, it will work on WPF but not Silverlight, and if the code is <sdk:GridSplitter/>, it will work on Silverlight but not WPF.

Is there a way to write this so that it works on both platforms?

+1  A: 

Yeah, in your wpf use this namespace: xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Then the tag is the same. You would just have to change the x:sdk tag to move from wpf to silverlight and back.

Rick Ratayczak
OK, but how do I use a different value for xmnls:sdk between wpf and Silverlight? I want the same Xaml code to work on both.
Daniel Plaisted
it would be the same xaml code except for that one line, there's not way that I know of to not change any lines.
Rick Ratayczak
+1  A: 

What I ended up doing was to create my own class that derived from GridSplitter.

public class MyGridSplitter : GridSplitter { }

Then I put an xmlns for my project at the top of my xaml file:

xmlns:local="clr-namespace:mynamespace"

And then I could just use the local namespace prefix for my GridSplitter:

<local:MyGridSplitter />
Daniel Plaisted
painful - but it works...
chadbr