如何判断(通过调试器是否正确加载了我的应用资源)。我试过(在f#中)
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>
和内容模板:
&LT;
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>
答案 0 :(得分:1)
要查看加载了哪些合并词典,请使用调试器监视窗口或代码查看:
Application.Current.Resources.MergedDictionaries.Count
Application.Current.Resources.MergedDictionaries[0].Count
etc...
如果您的资源字典似乎没有加载,则可能是您传入的源路径出现问题...
<ResourceDictionary Source="/FSSilverlightApp;component/TransitioningFrame.xaml" />
您的语法对于名为 FSSilverlightApp 的程序集以及项目/程序集根目录下的 TransitioningFrame.xaml 文件是正确的,因此请确保您的XAML文件位于那个位置。
如果要从同一个程序集加载资源字典,只需使用不带“程序集;组件/ ”语法的相对路径。我总是将我的资源字典放在Assets文件夹(Silverlight模板约定)中,并引用没有leadingh斜杠的文件,如...
<ResourceDictionary Source="Assets/Styles.xaml" />
祝你好运,