首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加WindowsFormsHost抛出XamlParseException

添加WindowsFormsHost抛出XamlParseException
EN

Stack Overflow用户
提问于 2016-11-30 21:53:53
回答 1查看 152关注 0票数 2

我试图使用FSharp.ChartingMainWindow中添加一个线条图。在MainViewModel我有-

代码语言:javascript
复制
let chart = Chart.Line [ for i in 0 .. 10 -> (i, i * i) ]
let control = new ChartControl(chart)
member self.LineChart = control

在xaml中-

代码语言:javascript
复制
<WindowsFormsHost Child="{Binding LineChart}" />

当我启动应用程序时,我获得了以下附加信息-

代码语言:javascript
复制
'Cannot create unknown type '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}WindowsFormsHost'.' Line number '20' and line position '10'.

如何解决这个问题?

这是@Foggy Finder。我删除了几行定义TextBlock和按钮的代码。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-01 00:33:25

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

不能在“WindowsFormsHost”类型的“子”属性上设置“绑定”。“绑定”只能设置在DependencyProperty的DependencyObject上。

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

代码语言:javascript
复制
<ContentControl Content="{Binding LineChart}" />

..。

代码语言:javascript
复制
member self.LineChart = new WindowsFormsHost(Child = control)

结果:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40898912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档