views:

72

answers:

1

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.Navigation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <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  A: 

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} />
Igor Zevaka
hmmm. adding the dictionary to the UserControl.Resources - seems to make everything work... Why do you think that would be? When the reference was in the app.xaml only I was able to get a refernece to the element via:let i2 : ControlTemplate = downcast Application.Current.Resources.MergedDictionaries.[0].["TransitioningFrame"]Which shows it is loaded - but the app still threw the exception
akaphenom
Not sure, perhaps a some kind of circular dependency throwing the spanner in the works? Maybe you can test whether or not this is your component that's having issues by placing a simple resource, like a Brush, in the merged dictionary and seeing if it's available in the control?
Igor Zevaka
absolutley I can muck around with it. But I think I have enough of this done, where I can pass it off to an engineer to pump some dummy tables etc in place for a demo. Having this app in 100% f# hasn't been easy - but thank you for helping me iron down one of the last "functional" unknowns.
akaphenom
Out of curiosity, why the choice of XAML/F#?
Igor Zevaka
I like the brevity of the F# language and find it very expressive. I am gonig to have my algo's and intelligence team switch to coding primarily in F# (as opposed to a mixture of Tsql / R /Matlab), and my services and infrastructure team as well. But that usage of F# is pretty well studied. I also wanted to see if I had the patience to code this app with so little knowledge of SIlverilght and only a primitive knowledge of F#. I learned alot in the process about thinks like: the relationship between XAML and the "codebehind" etc. It was fun
akaphenom