私は Web の最後まで行って戻ってきましたが、Z-Ordering WindowsFormsHost の問題に対する解決策が見つからないようです。私の問題は、項目が WindowsFormsHost でラップされた WinForm コントロールである ListBox のレンダリングに固有のものです。レンダリングすると、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);
}
}
助けてください :)