2010-05-24 68 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