首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在WPF中绑定包含ItemsControl项的WindowsFormHost

在WPF中绑定包含ItemsControl项的WindowsFormHost
EN

Stack Overflow用户
提问于 2013-10-16 19:08:23
回答 1查看 480关注 0票数 3

我正在为我们的WPF应用程序构建一个UI元素,它允许用户可视化以网格格式对齐的图形集合。据我所知,您可以使用ItemsControl和WrapPanel来很好地对齐网格格式的ui元素。

当我们尝试使用winforms图形库(zedgraph)生成图形时,就会遇到困难。这意味着我们必须使用WindowsFormsHost来显示图形视图。我尝试过使用普通的数据绑定来绑定图形集合,但它实际上不起作用:

XAML:

代码语言:javascript
运行
复制
<ItemsControl ItemsSource="{Binding Graphs}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <WindowsFormsHost Margin="5">
                <ui:Graph></ui:Graph>
            </WindowsFormsHost>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

上面的代码没有显示任何内容,但是访问了图形getter。

而且,即使我取消了绑定,只是在ItemsControl中插入了一些随机图视图.它仍然没有显示任何东西:

XAML:

代码语言:javascript
运行
复制
<ItemsControl>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <WindowsFormsHost Margin="5">
        <ui:Graph></ui:Graph>
    </WindowsFormsHost>
    <WindowsFormsHost Margin="5">
    </WindowsFormsHost>
        <ui:Graph></ui:Graph>
    </WindowsFormsHost>
    <WindowsFormsHost Margin="5">
        <ui:Graph></ui:Graph>
    </WindowsFormsHost>
</ItemsControl>

为了确保图形库的功能正常,这实际上显示了一个图形:

代码语言:javascript
运行
复制
<Grid>
    <WindowsFormsHost Margin="5">
        <ui:Graph></ui:Graph>
    </WindowsFormsHost>
</Grid> 

有人能引导我朝正确的方向前进吗?非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-18 14:32:19

这可能与布局有关。winforms是可怕的,并要求您硬编码的大小的一切。

尝试给winformshost一个固定的硬编码宽度和高度。

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

https://stackoverflow.com/questions/19411730

复制
相关文章

相似问题

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