我正在为我们的WPF应用程序构建一个UI元素,它允许用户可视化以网格格式对齐的图形集合。据我所知,您可以使用ItemsControl和WrapPanel来很好地对齐网格格式的ui元素。
当我们尝试使用winforms图形库(zedgraph)生成图形时,就会遇到困难。这意味着我们必须使用WindowsFormsHost
来显示图形视图。我尝试过使用普通的数据绑定来绑定图形集合,但它实际上不起作用:
XAML:
<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:
<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>
为了确保图形库的功能正常,这实际上显示了一个图形:
<Grid>
<WindowsFormsHost Margin="5">
<ui:Graph></ui:Graph>
</WindowsFormsHost>
</Grid>
有人能引导我朝正确的方向前进吗?非常感谢。
发布于 2013-10-18 14:32:19
这可能与布局有关。winforms是可怕的,并要求您硬编码的大小的一切。
尝试给winformshost一个固定的硬编码宽度和高度。
https://stackoverflow.com/questions/19411730
复制相似问题