【问题标题】:Silverlight ControlTemplate and F#Silverlight ControlTemplate 和 F#
【发布时间】:2010-05-24 19:27:53
【问题描述】:

有没有人成功地将 Silverlight ControlTemplate 整合到 F# Silverlight 应用程序中。我正在尝试向 Navgiation.Frame 元素添加过渡,并继续使用 C# 示例:http://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the-frame-control

下载的源代码使用模板 XAML 上的 MSBUILD:Compile 选项,并且该文件作为“页面”包含在内... ILDASM 不显示为 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>

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>

我的页面对象都使用以下代码加载它们各自的 xaml:

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

在应用启动的某个地方:

let p1 = new Page1()

我没有 ControlTemplate 的可比部分 - 虽然我希望应用程序对象和 App.xaml 将其拉入神奇地(顺便说一句,对这种魔法的依赖使得设置一个 100% f# silverlight 应用程序相当棘手 - 因为我发现几乎所有已发表的文章都是基于向导和捷径 - 很少涉及实际管道 - 呃)。

页面 xaml 通过以下方式引用控件:

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

感谢您对此主题的任何建议或想法。


根据 brians 的评论,我调查了 MSBUILD 命令诊断,除了将其作为资源包含之外,它看起来并没有做任何事情:

生成 .resources 文件: 'obj\Debug\TransitioningNavigation.g.resources'... (TaskId:14) 读取资源文件: 'C:\Users\todd.brown\Desktop\TransitioningNavigation\TransitioningNavigation\Assets\Styles.xaml'... (TaskId:14) 资源 ID 是 '资产/styles.xaml'。 (任务 ID:14)
读取资源文件: 'C:\Users\todd.brown\Desktop\TransitioningNavigation\TransitioningNavigation\Assets\TransitioningFrame.xaml'... (TaskId:14) 资源 ID 是 “资产/transitioningframe.xaml”。 (TaskId:14)


一件有趣的事情是,如果我重命名对 App.xaml 的 ContentTemplate xaml inide 的引用 - 应用程序无法加载并引发错误 - 所以我猜页面正在被正确引用和加载。也就是说,这很糟糕

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

【问题讨论】:

    标签: silverlight silverlight-3.0 f#


    【解决方案1】:

    转到命令行并运行可能很有用

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

    并检查诊断日志以找出“该 Xaml 文件(带有 ResourceDictionary)的 Compile 在幕后做了什么”。这可能暗示了要为 F# 做什么。

    【讨论】:

    • 不知道这个功能...好建议-thx。虽然我想知道 UI 是否应该手动编码转换或者首选技术是什么。看起来,TransitioningContentControl jsut 似乎免费连接了大约三个转换。而且它们看起来都不太复杂。
    【解决方案2】:

    好吧,我实际上是在 WPF 4.0 中编写了 ControlTemplates,所以这对 Silverlight 也应该很有效,请查看以下帖子和我提到的 git-hub 源代码,

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

    您应该大致了解如何声明资源、将它们与控件模板一起使用以及在自定义控件中加载控件模板。我也让 BLEND 以这种方式工作。

    如果您需要任何帮助,请告诉我。

    谢谢, 法赫德

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多