开发者

Iterating through StaticResource loaded by ResourceDictionary

Given a resource dictionary loading some static resources into memory - is there any way to iterate through theResources loaded into memory? My silverlight application keeps telling me it cannot find a static resource. I wonder if I have a naming convention issue or somehting - was hoping iterating through the resources in memory would help diagnose any issue...

I have the following 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>

and content template:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Na开发者_开发问答vigation"  
    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>


Resources defined in Application.Resources are implicitly available to all controls in the app, not sure about merged dictionaries. You can set a breakpoint in a control constructor and inspect this.Resources, this.Resources.MergedDictionaries, Application.Resources and Application.Resources.MergedDictionaries to see if your resource is there.

Also try to put the merged dictionaries in your control, see if that makes any difference:

<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} />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜