我已经到了网络的尽头并回来了,我似乎无法为我的 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);
}
}
请帮忙 :)