Если я перемещаю ресурсы приложения в ресурсы UserControl, каждый из них запускает groovy. Я до сих пор не понимаю, почему.Исключение ControlTemplate: «XamlParseException: не удается найти ресурс с именем/ключом»
Я заметил, что мой объект приложения MyApp сделал больше, чем наследовать от применения его загрузили XAML для основного шаблона и подключена вся сантехника. Поэтому я решил создать пользовательский элемент управления для удаления шаблона из приложения (думая, что может быть проблема с ордером, не позволяющая найти мой ресурс).
namespace Module1
type Template() as this =
//inherit UriUserControl("/FSSilverlightApp;component/template.xaml", "")
inherit UriUserControl("/FSSilverlightApp;component/templateSimple.xaml", "")
do
Application.LoadComponent(this, base.uri)
let siteTemplate : Grid = (this.Content :?> FrameworkElement) ? siteTemplate
let nav : Frame = siteTemplate ? contentFrame
let pages : UriUserControl array = [|
new Module1.Page1() :> UriUserControl ;
new Module1.Page2() :> UriUserControl ;
new Module1.Page3() :> UriUserControl ;
new Module1.Page4() :> UriUserControl ;
new Module1.Page5() :> UriUserControl ; |]
do
nav.Navigate((pages.[0] :> INamedUriProvider).Uri) |> ignore
type MyApp() as this =
inherit Application()
do Application.LoadComponent(this, new System.Uri("/FSSilverlightApp;component/App.xaml", System.UriKind.Relative))
do
System.Windows.Browser.HtmlPage.Plugin.Focus()
this.RootVisual <- new Template() ;
// test code to check for the existance of the ControlTemplate - it exists
let a = Application.Current.Resources.MergedDictionaries
let b = a.[0]
let c = b.Count
let d : ControlTemplate = downcast c.["TransitioningFrame"]
()
"/FSSilverlightApp;component/templateSimple.xaml"
<UserControl x:Class="Module1.Template"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid HorizontalAlignment="Center" Background="White"
Name="siteTemplate">
<StackPanel Grid.Row="3" Grid.Column="2" Name="mainPanel">
<!--Template="{StaticResource TransitioningFrame}"-->
<navigation:Frame Name="contentFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Template="{StaticResource TransitioningFrame}"/>
</StackPanel>
</Grid>
</UserControl>
"/FSSilverlightApp;component/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>
«/FSSilverlightApp;component/TransitioningFrame.xaml "
<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="Olive"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="5"
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>
Unfortun что это не сработало. Если я удалю атрибут шаблона из элемента navigationFrame, приложение загружает и направляет область содержимого на первую страницу в массиве страниц. Ссылка на этот ресурс продолжает выдавать ошибку, не найденную ресурсом.
Оригинал Сообщение
У меня есть следующие App.xaml (с помощью Silverlight 3)
<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>
отладчик говорит его ContentTemplate является правильно загруженный, добавив минимальный код:
типа MyApp(), так как это = наследует приложения() сделать Application.LoadComponent (это, новый System.Uri ("/ FSSilverlightApp; компонент/App.xaml", System.UriKind.Relative))
let cc = new ContentControl()
let mainGrid : Grid = loadXaml("MainWindow.xaml")
do
this.Startup.Add(this.startup)
let t = Application.Current.Resources.MergedDictionaries
let t1 = t.[0]
let t2 = t1.Count
let t3: ControlTemplate = t1.["TransitioningFrame"]
С этой линией в моей main.xaml
<navigation:Frame Name="contentFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Template="{StaticResource TransitioningFrame}"/>
Урожайность этого исключения
сведения об ошибках веб-странице
Пользовательский агент: Mozilla/4.0 (совместим; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E) Отметка: Пн, 24 мая 2010 23:10:15 UTC
сообщение: Неизвестное Ошибка в Silverlight Application Код: 4004
Категория: ManagedRuntimeError
Сообщение: System.Windows.Markup ,XamlParseException: Не удается найти ресурс с Name/Key TransitioningFrame [Line: 86 Позиция: 115] в MS.Internal.XcpImports.CreateFromXaml (String xamlString, Boolean createNamescope, булевой requireDefaultNamespace, булевых allowEventHandlers, Boolean expandTemplatesDuringParse) при MS.Internal.XcpImports.CreateFromXaml (String xamlString, булева createNamescope, Логическое requireDefaultNamespace, Boolean allowEventHandlers) при System.Windows.Markup.XamlReader.Load (String XAML) при Globals.loadXaml [T] (Строка xam lPath) в Module1.MyApp..ctor()линии: 54 Char: 13 Код: 0 URI: файла: /// C: /fsharp/FSSilverlightDemo/FSSilverlightApp/bin/Debug/SilverlightApplication2TestPage.html