鉴于资源字典将一些静态资源加载到内存中 - 有没有办法迭代加载到内存中的资源?我的silverlight应用程序一直告诉我它无法找到静态资源。我想知道我是否有一个命名约定问题或某些问题 - 希望迭代内存中的资源有助于诊断任何问题......
我有以下app.xaml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Module1.MyApp">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FSSilverlightApp;component/TransitioningFrame.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
和内容模板:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ControlTemplate x:Key="TransitioningFrame" TargetType="navigation:Frame">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<ContentPresenter Cursor="{TemplateBinding Cursor}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"/>
</Border>
</ControlTemplate>
</ResourceDictionary>
答案 0 :(得分:1)
Application.Resources中定义的资源隐式可用于应用程序中的所有控件,不确定合并的字典。您可以在控件构造函数中设置断点,并检查this.Resources
,this.Resources.MergedDictionaries
,Application.Resources
和Application.Resources.MergedDictionaries
以查看您的资源是否存在。
还尝试将合并的词典放在您的控件中,看看是否有任何区别:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FSSilverlightApp;component/TransitioningFrame.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<!--Use the style later in the same file-->
<navigation:Frame Style={StaticResource TransitioningFrame} />