WindowsFormHost elements in WPF ListBox - Z-Order

I was to the end of the Internet and back, and I can not find a solution for my Z-Ordering WindowsFormsHost Issue. My problem is specific to creating a ListBox where WindowsFormsHost elements are wrapped in WinForm controls. When all items are displayed, even those that are outside the ListBox are displayed, which makes the whole screen horrible.

I am adding a quick code example. Do I have any options? Should I rethink my layout?

    <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>

and codebehind:

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

Please, help:)

+3
source share
1 answer

AirSpace. Winforms WPF, . , .

.

, WinForms - (.. ) .

+1

All Articles