我试图使用FSharp.Charting在MainWindow中添加一个线条图。在MainViewModel我有-
let chart = Chart.Line [ for i in 0 .. 10 -> (i, i * i) ]
let control = new ChartControl(chart)
member self.LineChart = control在xaml中-
<WindowsFormsHost Child="{Binding LineChart}" />当我启动应用程序时,我获得了以下附加信息-
'Cannot create unknown type '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}WindowsFormsHost'.' Line number '20' and line position '10'.如何解决这个问题?
这是@Foggy Finder。我删除了几行定义TextBlock和按钮的代码。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ViewModels;assembly=AsyncFS"
xmlns:fsxaml="http://github.com/fsprojects/FsXaml"
Title="MVVM and XAML Type provider" Height="200" Width="400">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<WindowsFormsHost Child="{Binding LineChart}" />
</Grid>发布于 2016-12-01 00:33:25
为了使用WinfowsFormsHost,您需要添加对WindowsFormsIntegration的引用。但如果你这么做,你就会得到:
不能在“WindowsFormsHost”类型的“子”属性上设置“绑定”。“绑定”只能设置在DependencyProperty的DependencyObject上。
修复的简单方法是直接创建对象:
<ContentControl Content="{Binding LineChart}" />..。
member self.LineChart = new WindowsFormsHost(Child = control)结果:

https://stackoverflow.com/questions/40898912
复制相似问题