简体   繁体   English

Silverlight ControlTemplate和F#

[英]Silverlight ControlTemplate and F#

Has anybody had any success incorporating a Silverlight ControlTemplate into an F# Silverlight application. 是否有人成功将Silverlight ControlTemplate集成到F#Silverlight应用程序中。 I am trying to add transitions to the Navgiation.Frame element and following along on with a C# example: http://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the-frame-control 我正在尝试将过渡添加到Navgiation.Frame元素,然后再添加一个C#示例: http ://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the -框架控制

The downloaded source uses the MSBUILD:Compile option on the template XAML and the file is included as a "Page"... ILDASM doesn't show any object created for the XAML; 下载的源代码使用模板XAML上的MSBUILD:Compile选项,并且该文件作为“页面”包含在内。ILDASM不显示为XAML创建的任何对象;它只显示XAML。

In my project I incldued it as a "Resource" (same as I have done for my pages) and referenced it in app.xaml: 在我的项目中,我将其包含为“资源”(与我为页面所做的相同),并在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>

the TransitioningFrame.xaml is as follows: TransitioningFrame.xaml如下:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit">
    <ControlTemplate x:Key="TransitioningFrame" TargetType="navigation:Frame">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
            <toolkit:TransitioningContentControl Content="{TemplateBinding Content}"
                                                 Cursor="{TemplateBinding Cursor}"
                                                 Margin="{TemplateBinding Padding}"
                                                 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                 VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                 HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                 VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                 Transition="DefaultTransition" />
        </Border>
    </ControlTemplate>
</ResourceDictionary>

My page objects all load their respective xaml with the follwoing code: 我的页面对象都使用以下代码加载各自的xaml:

type Page1() as this =
    inherit UriUserControl("/FSSilverlightApp;component/Page1.xaml")
    do
        Application.LoadComponent(this, base.uri)

and somewhere in app startup: 在应用启动的某个位置:

let p1 = new Page1()

I donot have a comparable piece for the ControlTemplate - though I was hoping the application object and App.xaml would pull it in magically (as an aside, the reliance on this magic has made setting up a 100% f# silverlight application rather tricky - as nearly all the published articles I find are based around wizards and short cuts - very little on the acual plumbing - ugh). 我没有ControlTemplate的类似版本-尽管我希望应用程序对象和App.xaml能够神奇地将其拉入(顺便说一句,对这种魔术的依赖使得设置100%f#silverlight应用程序非常棘手-我发现几乎所有已发表的文章都是围绕着向导和快捷方式编写的-很少涉及实际的管道-嗯)。

the page xaml references the control via: xaml页面通过以下方式引用控件:

<StackPanel Grid.Row="3" Grid.Column="2" Name="mainPanel">
     <navigation:Frame Name="contentFrame" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"  Template="{StaticResource TransitioningFrame}"/>
</StackPanel>

Any advice or thougts on the subject are appreciated. 关于这个问题的任何建议或想法都值得赞赏。


Per brians comment, I investigated the MSBUILD command diagnostics and it doesn't look like it does anythining other than include it as a resource: 根据brians的评论,我调查了MSBUILD命令诊断程序,除了将其包括为资源之外,它似乎没有做任何其他事情:

Generating .resources file: 'obj\\Debug\\TransitioningNavigation.g.resources'... (TaskId:14) Reading Resource file: 'C:\\Users\\todd.brown\\Desktop\\TransitioningNavigation\\TransitioningNavigation\\Assets\\Styles.xaml'... (TaskId:14) Resource ID is 'assets/styles.xaml'. 生成.resources文件:'obj \\ Debug \\ TransitioningNavigation.g.resources'...(TaskId:14)读取资源文件:'C:\\ Users \\ todd.brown \\ Desktop \\ TransitioningNavigation \\ TransitioningNavigation \\ Assets \\ Styles.xaml' ...(TaskId:14)资源ID为'assets / styles.xaml'。 (TaskId:14) (TaskId:14)
Reading Resource file: 'C:\\Users\\todd.brown\\Desktop\\TransitioningNavigation\\TransitioningNavigation\\Assets\\TransitioningFrame.xaml'... (TaskId:14) Resource ID is 'assets/transitioningframe.xaml'. 读取资源文件:'C:\\ Users \\ todd.brown \\ Desktop \\ TransitioningNavigation \\ TransitioningNavigation \\ Assets \\ TransitioningFrame.xaml'...(TaskId:14)资源ID为'assets / transitioningframe.xaml'。 (TaskId:14) (TaskId:14)


Well one interesting thing is that If I rename the reference to the ContentTemplate xaml inide of the App.xaml - the application deosn't load and throws an error - so I guess the page is being referenced and loaded correctly. 好一件有趣的事情是,如果我将对App.xaml的ContentTemplate xaml索引的引用重命名,则该应用程序将不会加载并引发错误-因此我猜该页面已被正确引用和加载。 ie this is bad 即这很糟糕

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

It may be useful to go to the command line, and run 转到命令行并运行可能会很有用

msbuild /t:clean
msbuild /v:diag > diagnostics.txt

and inspect the diagnostic log to find out 'what the Compile of that Xaml file (with the ResourceDictionary ) is doing under the hood'. 并检查诊断日志以找出“该Xaml文件(使用ResourceDictionary )在后台进行的Compile ”。 This may be suggestive of what to do for F#. 这可能暗示了对F#做什么。

Well, I actually wrote ControlTemplates in WPF 4.0, so this should pretty much work for Silverlight too, check the below posts and the git-hub source that I have mentioned, 好吧,我实际上是在WPF 4.0中编写ControlTemplates的,所以这对于Silverlight来说也应该很有效,请查看以下文章和我提到的git-hub源代码,

http://fadsworld.wordpress.com/2011/03/05/f-wpf-component-development/ http://fadsworld.wordpress.com/2011/03/05/f-wpf-component-development/

You should pretty much get the idea about how to declare resources, use them with control templates and also load control templates inside a custom control. 您应该对如何声明资源,将其与控件模板一起使用以及将控件模板加载到自定义控件中的想法有所了解。 I also got BLEND working in this way. 我也让BLEND以这种方式工作。

Let me know if you need any help. 让我知道您是否需要任何帮助。

Thanks, Fahad 谢谢,法哈​​德

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM