【问题标题】:WindowsFormHost items in a WPF ListBox - Z-OrderWPF ListBox 中的 WindowsFormHost 项 - Z-Order
【发布时间】:2011-08-22 22:16:57
【问题描述】:

我已经到了网络的尽头并回来了,我似乎找不到任何解决我的 Z-Ordering WindowsFormsHost 问题的方法。我的问题特定于呈现一个 ListBox,其中项目是 WindowsFormsHost 包装的 WinForm 控件。渲染时,所有项目都会显示,即使是 ListBox 边界之外的项目——这使得整个屏幕看起来很糟糕。

我附上了一个快速代码示例。我有什么选择吗?我需要重新考虑我的布局吗?

    <Window x:Class="WFH_ZOrderIssue.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
  xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
  Title="WFH ListBox ZOrder" Height="300" Width="600">
 <Grid>
  <ListBox Background="LightBlue" HorizontalAlignment="Left" ItemsSource="{Binding}" MaxWidth="400" BorderThickness="0" 
     ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.CanContentScroll="False" 
     ScrollViewer.HorizontalScrollBarVisibility="Auto"
     SelectionMode="Extended" x:Name="lstDisplays" 
     >
   <ListBox.ItemTemplate>
    <DataTemplate>
     <ScrollViewer x:Name="viewer" VerticalScrollBarVisibility="Hidden" >
      <wfi:WindowsFormsHost Margin="20,0" x:Name="host">
       <wf:Button Text="WindowFormsHost - The Ugly" />
      </wfi:WindowsFormsHost>
     </ScrollViewer>
    </DataTemplate>
   </ListBox.ItemTemplate>
   <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
     <StackPanel Orientation="Horizontal" />
    </ItemsPanelTemplate>
   </ListBox.ItemsPanel>
  </ListBox>
 </Grid>
</Window>

和代码隐藏:

    /// <summary>
 /// Interaction logic for Window1.xaml
 /// </summary>
 public partial class Window1 : Window
 {
  public Window1()
  {
   InitializeComponent();
   this.DataContext = System.Linq.Enumerable.Range(0, 30);
  }
 }

请帮忙:)

【问题讨论】:

    标签: wpf winforms listbox z-order windowsformshost


    【解决方案1】:

    这被称为AirSpace 问题。 Winforms 将在 WPF 之上进行渲染,因为两者都使用不同的渲染技术。有一些解决方案,但不是直截了当的。

    看看this blog entryhere,你可能会开始工作。

    如果这不起作用,我建议不要将 WinForms 放置在低于顶层的任何位置(即在窗口上),并确保不要对布局做任何花哨的事情。

    【讨论】:

    • 两个链接都不再可用
    猜你喜欢
    • 2013-10-25
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多