添加WindowsFormsHost会抛出XamlParseException

时间:2016-11-30 21:53:54

标签: wpf f# windowsformshost fsxaml

我试图在$results = $app->screeners()->where(function($query) use($searchTerm) { // Notice also the addition of the placeholder ('%') character $query->where('title', 'LIKE', '%' . $searchTerm . '%') ->orWhere('description', 'LIKE', '%' . $searchTerm . '%') ; })->get(); 中使用FSharp.Charting添加折线图。在MainViewModel中我有 -

MainWindow

和xaml -

let chart = Chart.Line [ for i in 0 .. 10 -> (i, i * i) ]
let control = new ChartControl(chart)
member self.LineChart = control

当我启动应用程序时,我会获得<WindowsFormsHost Child="{Binding LineChart}" /> 以下附加信息 -

XamlParseException

如何解决问题?

这是@Foggy Finder。我删除了几行定义TextBlock和Buttons。

'Cannot create unknown type '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}WindowsFormsHost'.' Line number '20' and line position '10'.

1 个答案:

答案 0 :(得分:1)

要使用WinfowsFormsHost,您需要添加对WindowsFormsIntegration的引用。但如果你这样做,你会得到:

  

无法在类型的“Child”属性上设置“绑定”   'WindowsFormsHost'。 '绑定'只能在a上设置   DependencyObject的DependencyProperty。

简单的修复方法是直接创建对象:

<ContentControl Content="{Binding LineChart}" />

...

member self.LineChart = new WindowsFormsHost(Child = control)

结果:

enter image description here