Silverlight ControlTemplate and F#
Has anybody had any success incorporating a Silverlight ControlTemplate into an F# Silverlight application. I am trying to add transitions to the Navgiation.Frame element and followi开发者_如何学Gong along on with a C# example: http://www.davidpoll.com/2009/07/19/silverlight-3-navigation-adding-transitions-to-the-frame-control
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;
In my project I incldued it as a "Resource" (same as I have done for my pages) and referenced it in 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:
<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:
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).
the page xaml references the control via:
<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:
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'. (TaskId:14)
Reading Resource file: 'C:\Users\todd.brown\Desktop\TransitioningNavigation\TransitioningNavigation\Assets\TransitioningFrame.xaml'... (TaskId:14) Resource ID is 'assets/transitioningframe.xaml'. (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. 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'. This may be suggestive of what to do for 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,
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.
Let me know if you need any help.
Thanks, Fahad
精彩评论