2010-05-24 28 views
0

如何判断(通过调试器是否正确加载了我的应用程序资源)。我试过(在f#中)如何确定ResourceDictionary是否正确加载

type MyApp() as this = 
    inherit Application() 
     do Application.LoadComponent(this, new System.Uri("/FSSilverlightApp;component/App.xaml", System.UriKind.Relative)) 

    let cc = new ContentControl() 

    let mainGrid : Grid = loadXaml("MainWindow.xaml") 
    let siteTemplate : Grid = mainGrid 

    let txt : TextBlock = siteTemplate ? txt 

    do 
     this.Startup.Add(this.startup) 
     let mutable s = "Items: " 
     s <- s + this.Resources.Count.ToString() 

它返回的计数为零。虽然我非常肯定应用程序正在加载资源,因为如果我在App.xaml内更改路径 - 我在运行时会遇到异常。其他重,lavent片段是:

我有以下的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

要查看其合并字典加载,使用调试器观察窗口或代码看看:

Application.Current.Resources.MergedDictionaries.Count 
Application.Current.Resources.MergedDictionaries[0].Count 
etc... 

如果你的资源字典似乎没有被加载,也可能是跟你传递到源路径的问题......

<ResourceDictionary Source="/FSSilverlightApp;component/TransitioningFrame.xaml" /> 

你的语法看起来是正确的名为FSSilverlightApp的组件,并且对于项目/程序集根中的TransitioningFrame.xaml文件,请确保您的XAML文件位于该位置。

如果要从同一程序集加载资源词典,只需使用不含“程序集;组件/”语法的相对路径。我总是把我的资源字典中的资产文件夹(Silverlight的模板约定)和参考文件,而不leadingh斜线,如...

<ResourceDictionary Source="Assets/Styles.xaml" /> 

祝你好运,
吉姆·麦柯迪,YinYangMoney和脸Face Software

+0

对VS2010 rc1中f#应用程序中的文件夹没有太多支持。感谢指针,我会仔细检查该属性,看看它是否加载。 – akaphenom 2010-05-24 22:48:20