C# wpf silverlight多目标资源字典
我正在编写一些多目标应用程序.NET4.0。我的字典有问题。 脚本: 创建WPF CustomControlLibrary-将其命名为WpfLib,默认名称空间测试 在WpfLib中创建UserControl-将其命名为ucC# wpf silverlight多目标资源字典,c#,wpf,silverlight,C#,Wpf,Silverlight,我正在编写一些多目标应用程序.NET4.0。我的字典有问题。 脚本: 创建WPF CustomControlLibrary-将其命名为WpfLib,默认名称空间测试 在WpfLib中创建UserControl-将其命名为uc <UserControl x:Class="test.uc" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="ht
<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>
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>
现在一切都很好……按钮是红色的
现在,让我们添加新的Project Silverlight应用程序,并将其命名为SlApp Silverlight 5namespace test
让我们将WpfLib中的uc添加为linkuc.xaml uc.xaml.cs。
在SlApp中创建新的ResourceDictionary,并将其命名为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="Button">
<Setter Property="Background" Value="Blue" />
</Style>
</ResourceDictionary>
New ResourceDictionary具有TargetType=按钮,因为SilverLight中不支持x:Type。背景设置为蓝色而不是红色
问题就从这里开始。
我如何让它工作?控件uc在mergingin Silverlight版本上显示错误。我需要在Wpf和Silverlight版本的usercontrol上使用不同的ResourceDictionary。ClassLibrary不支持app.xaml,我不能使用默认样式。TargetType=Button也适用于C sharp wpf项目。