請注意,我使用特定於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