Using GridSplitter in a Xaml file for both Silverlight and WPF
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 Silver开发者_如何学Clight but not WPF.
Is there a way to write this so that it works on both platforms?
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 />
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.
精彩评论