How to declare Labels in xaml for use in both WPF and Silverlight

I am working on a UserControl in a Silverlight project in visual studio 2010.

This user control uses Labels as follows:

<sdk:Label .../>
-or-
<sdk:Label>
  singleObject
</sdk:Label>
-or-
<sdk:Label>stringContent</sdk:Label>   

as described here

However, when I create a WPF project link it to Silverlight Library Project:

(by adding existing items (Add Link) to cs classes and the .xaml file defining the control)

I get the following error in build:

The tag 'Label' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'. Line 49 Position 18. myfile.xaml 49 18 MyLibraryWPF

This doc shows that labels in WPF are declared without the sdk:

like this:

<Label>
  Content
</Label>

yet, I cannot change that in my Silverlight project. It will be a real waste to create a whole new project and duplicate the code to make it work.

How to make the Labels work with both Silverlight and WPF projects?


Here is a piece of Code in xaml that can be shared by WPF and Silverlight and looks like label with Background coloe:

<Border Margin="3,0,3,3" Background="#FF00B050">
                <TextBlock Text="txt122" FontSize="13" FontWeight="SemiBold" Height="21" Name="label15" Width="133"  ></TextBlock>
            </Border>

This means that a Label cannot be used in a shared XAML.

链接地址: http://www.djcxy.com/p/34490.html

上一篇: 文字方向

下一篇: 如何在xaml中声明标签以用于WPF和Silverlight