我正在使用VS2008。我上过这门课
[System.Windows.Markup.ContentProperty("Child")]
public class CaptionedBox : Control
{
static CaptionedBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CaptionedBox),
new FrameworkPropertyMetadata(typeof(CaptionedBox)));
}
public static readonly DependencyProperty ShadeVisibilityProperty =
DependencyProperty.Register(
"ShadeVisibility", typeof(Visibility), typeof(CaptionedBox), new
PropertyMetadata(Visibility.Hidden));
}并将此代码保存在ResourceDictionary (名为Generic.xaml的文件)中
<ControlTemplate TargetType="{x:Type wft:CaptionedBox}">
<Grid>
...
<Rectangle Fill="#44000000" Visibility="{TemplateBinding ShadeVisibility}"/>
</Grid>
</ControlTemplate>没有错误,没有问题,我到处都在用这个CaptionedBox。
我在同一项目中还有另一个XAML页面,它使用Source="../Themes/Generic.xaml“引用这个ResourceDictionary。当我打开该页面时,它显示“资源字典XAML文件有错误,无法加载”。它在这一点上指的是Generic.XAML。如果我双击错误消息,即使在VS2008中打开了Generic.xaml,我也会得到一个不同的Generic.XAML的不同选项卡,只是内容是相同的,如果我复制每个选项卡的完整路径,我会看到:
C:\Source\LyonsForge\root\PumpServicing\branches\PSRT_1__2\Code\Bench\Controls\Wizard..\Themes\Generic.xaml C:\Source\LyonsForge\root\PumpServicing\branches\PSRT_1__2\Code\Bench\Controls\Themes\Generic.xaml
虽然有点尴尬,但它们是相同的路径。
有什么线索吗?
发布于 2011-10-06 02:28:46
你已经把你的generic.xaml设为本地拷贝了吗?另外,不要忘记在文件的属性上设置选项:"Copy to output directory“为"Copy always",因为generic.xaml不是用来编译的。
https://stackoverflow.com/questions/7665773
复制相似问题