wpf silverlight multi

I'm writing some multi-targeting application (.net 4.0). I have problems with ResourceDictionay. Scenario: Create WPF CustomControlLibrary - name it "WpfLib", default Namespace "test" In WpfLib create UserControl - name it "uc"

<UserControl x:Class="test.uc"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="res.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>   
    <Grid>
        <Button Style="{StaticResource bStyle}" Content="Button" Height="23"  Width="75" />
    </Grid>
</UserControl>

Code for "res.xaml"

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="bStyle" TargetType="{x:Type Button}">
        <Setter Property="Background" Value="Red" /> 
    </Style>
</ResourceDictionary>

Everything is great now....Button is Red

Now lets add new Project Silverlight Application and name it "SlApp" (Silverlight 5)(namespace "test") Lets add "uc" from "WpfLib" as link("uc.xaml" "uc.xaml.cs" ). Create new ResourceDictionary in "SlApp" and name it res.xaml like this:

 <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Style x:Key="bStyle" TargetType="Button">
            <Setter Property="Background" Value="Blue" />
        </Style>
    </ResourceDictionary>

New ResourceDictionary has TargetType="Button" because x:Type is not supported in SilverLight. Background is set to color Blue not red.

And here starts the problem.
How do i make it work? Control uc displays error on merging(in Silverlight version). I need different ResourceDictionary on Wpf and Silverlight version of usercontrol. ClassLibrary doesn't support app.xaml and i can't use default style.

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

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

下一篇: wpf silverlight多