2016-11-30 78 views
2

我试图在MainWindow添加使用FSharp.Charting折线图。在MainViewModel我有 -添加WindowsFormsHost抛出XamlParseException

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}" /> 

当我启动应用程序,我得到XamlParseException具有以下附加信息 -

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

如何解决这个问题?


这是@Foggy Finder。我已经删除了定义TextBlock和Buttons的几行代码。

<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> 
+1

为什么不使用'OxyPlot'或“LiveCharts”? –

+1

你可以显示完整的XAML(或至少它的标题)吗? –

+0

'FSharpCharting'似乎比'LiveChart'更容易。我还不熟悉OxyPlot' @FoggyFinder –

回答

2

为了使用WinfowsFormsHost,你需要添加一个引用到WindowsFormsIntegration。但是,如果你这样做,你会得到:

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

简单的方法来解决是直接创建对象:

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

...

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

结果:

enter image description here

+0

不错,它的作品。 –

相关问题