Trouble in Displaying WindowsFormHosts controls in a ListBox in WPF RRS feed

  • Question

  •       I have a requirement to display 3rd party controls in a ListBox that obviously need to be wrapped with WindowsFormsHost controls. The items in the list box are stretching outside the bounds of the parent listBox control - obvious airspace issue - when I scroll the list back and forth. I do NOT have the option to display the list in its own window either. I need to ensure my list items display and remain contained within the bounds of the parent listBox.

        I can't seem to find any solution for my Z-Ordering WindowsFormsHost Issue. My issue is specific to rendering a ListBox where the items are WindowsFormsHost wrapped WinForm controls. When rendered all the items are displayed even those outside the bounds of the ListBox -- which makes the entire screen look horrible.

    I am attaching a quick code sample. Do I have any options? Do I need to rethink my layout?

    <Window.Resources> <DataTemplate x:Key="DataTemplate2"> <Grid x:Name="bubblegrid"> <Grid x:Name="bubble_left" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" Visibility="{Binding showleft}"> <Grid.Width> <System:Double>NaN</System:Double> </Grid.Width> <!--<Grid.RenderTransform> <CompositeTransform/> </Grid.RenderTransform>--> <Grid.ColumnDefinitions> <ColumnDefinition Width="23"/> <ColumnDefinition/> <ColumnDefinition Width="16"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="13"/> <RowDefinition/> <RowDefinition Height="13"/> </Grid.RowDefinitions> <Grid x:Name="upper_left2" Height="13" Margin="0" Width="23"> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="image/4_03.png"/> </Grid.Background> </Grid> <Grid x:Name="upper_right2" Height="13" Margin="0" Width="16" Grid.Column="2"> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="image/4_01.png"/> </Grid.Background> </Grid> <Grid x:Name="lower_left2" Height="13" Margin="0" Width="23" Grid.Row="2"> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="image/4_09.png"/> </Grid.Background> </Grid> <Grid x:Name="lower_right2" Height="13" Margin="0" Width="16" Grid.Column="2" Grid.Row="2"> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="image/4_07.png"/> </Grid.Background> </Grid> <Grid x:Name="left2" Margin="0" Width="23" Grid.Row="1"> <Grid.Background> <ImageBrush ImageSource="image/4_06.png" Stretch="None"/> </Grid.Background> </Grid> <Grid x:Name="center2" Grid.Column="1" Margin="0" Grid.Row="1"> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="image/4fill.png"/> </Grid.Background> <WindowsFormsHost HorizontalAlignment="Center" MaxWidth="240" VerticalAlignment="Center"> <Msg:MyExtRichTextBox x:Name="msgbubble2" AutoSize="True"></Msg:MyExtRichTextBox> </WindowsFormsHost> </Grid> <Grid x:Name="right2" Margin="0" Width="16" Grid.Row="1" Grid.Column="2"> <Grid.Background> <ImageBrush ImageSource="image/4_04.png" Stretch="None"/> </Grid.Background> </Grid> <Grid x:Name="upper2" Grid.Column="1" Height="13" Margin="0"> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="image/4_02.png"/> </Grid.Background> </Grid> <Grid x:Name="lower2" Grid.Column="1" Height="13" Margin="0,-3,0,0" Grid.Row="2"> <Grid.Background> <ImageBrush Stretch="Fill" ImageSource="image/4_08.png"/> </Grid.Background> </Grid> </Grid> <Grid x:Name="LayoutRoot" Background="Transparent"/> </Grid> </DataTemplate> </Window.Resources>

    and call the DataTemplate here :

      <Grid x:Name="ContentPanel" Margin="0,40,254,0" Grid.Row="1">
             <ListBox x:Name="list" Margin="0" ItemTemplate="{StaticResource DataTemplate2}" Height="328" Background="White" Width="341">
                            <Style TargetType="ListBoxItem">
                                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>

    Please help and give me a solution to how to fix this issue ,Thanks in advance!

    • Edited by Steve Ice Monday, May 28, 2012 6:18 AM
    Monday, May 28, 2012 3:19 AM


All replies