请注意,我使用特定于WPF的F#。在任何深度设置DataContext的子控件应该怎么做?特别是如何设置数据上下文以控制名称“TargetControl”。问题背景:如何继承DataContext?
的App.xaml:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Frame Name="Frame" Source="MainWindow.xaml" />
</Window>
MainWindow.xaml:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<TabControl Grid.Row="0" Grid.Column="0" Name="mainTab">
<!-- Tests work area -->
<TabItem Header="Проверка проекта">
<Frame Source="TestsPropagate.xaml" />
</TabItem>
</TabControl>
</Grid>
</UserControl>
TestsPropagate.xaml
<UserControl
Name="TargetControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBox Text="{Binding Path=testField}" />
</UserControl>
我的引导程序来启动这个上限:
[<STAThread>]
[<EntryPoint>]
let main(_) = //(new Application()).Run(Application.Current) //mainWindowViewModel)
OFTD.DOM.ExtraEntities.Verification.EnitiesInitializer.InitializeReaders()
let app = new Application()
let view = Application.LoadComponent(new System.Uri("App.xaml", UriKind.Relative)) :?> Window
let vm = new AppViewModel() // is data context to TargetControl
app.Run(view)
哇,WPF和F#,你是勇敢的:) – GONeale 2012-06-26 07:10:04
现在我用F#只在程序的内核并实现视图模型。然后,我在C#代码中展开视图模型(用于后面的代码),并在C#中使用WPF与F#的视图模型:) – psct 2012-07-31 11:37:17