迭代ResourceDictionary加载的StaticResource

时间:2010-05-26 00:56:37

标签: wpf silverlight silverlight-3.0

鉴于资源字典将一些静态资源加载到内存中 - 有没有办法迭代加载到内存中的资源?我的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>

1 个答案:

答案 0 :(得分:1)

Application.Resources中定义的资源隐式可用于应用程序中的所有控件,不确定合并的字典。您可以在控件构造函数中设置断点,并检查this.Resourcesthis.Resources.MergedDictionariesApplication.ResourcesApplication.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} />