Click here to Skip to main content
15,893,989 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a source which is:

C#
private ObservableCollection<Tuple<string,WrapPanel>> _list = new ObservableCollection<Tuple<string, WrapPanel>>();



Also I have a Listbox :

C#
<ListBox  SelectionMode="Single"   x:Name="Display" VerticalAlignment="Top"  HorizontalAlignment="Stretch"  MinHeight="100" MinWidth="700" MaxHeight="250"



I set the itemssource from this listboz to my collection source :
C#
Display.ItemsSource = _List;


I would like to display the content of WrapPanels ( Item2) into my listbox. I can not find the way to correctly visualize those wrapPanels obsjects .

I have tried different things in order to visualize those WrapPanels correctly

<!--1-->
XML
 <ListBox  SelectionMode="Single"   x:Name="MFPanelsDisplay" VerticalAlignment="Top"  HorizontalAlignment="Stretch"  MinHeight="100" MinWidth="700" MaxHeight="250"                                       >
 <ListBox.ItemsPanel>

                                        <ItemsPanelTemplate>
                                            <WrapPanel IsItemsHost="True" DataContext="{Binding}"  />
                                        </ItemsPanelTemplate>
                                    </ListBox.ItemsPanel>
</Listbox>

<!--2-->
XML
<ListBox  SelectionMode="Single"   x:Name="MFPanelsDisplay" VerticalAlignment="Top"  HorizontalAlignment="Stretch"  MinHeight="100" MinWidth="700" MaxHeight="250" DisplayMemberPath="Item2"/>

<!--3-->
</ListBox.ItemTemplate>
                                 <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <Grid>
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>
  <WrapPanel Grid.Column="0"  Binding="{Binding Item2}"  />
  <TextBlock Grid.Column="1" Text="{Binding Item1}"/>
                                            </Grid>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>



The result is always :
System.Windows.Controls.WrapPanel
System.Windows.Controls.WrapPanel
System.Windows.Controls.WrapPanel
System.Windows.Controls.WrapPanel

Any help would be good.
Posted
Updated 15-Dec-15 23:55pm
v4

1 solution

I just found what I was looking for :

XML
<ListBox.ItemTemplate>
                                     <DataTemplate>
                                         <Grid>
                                             <Grid.ColumnDefinitions>
                                                 <ColumnDefinition/>
                                                 <ColumnDefinition/>
                                             </Grid.ColumnDefinitions>
  <ContentControl Grid.Column="0" Content="{Binding Item2}" />
  <TextBlock Grid.Column="1" Text="{Binding Item1}"/>
                                         </Grid>
                                     </DataTemplate>
                                 </ListBox.ItemTemplate>
                             </ListBox>

ContentControl was the key for display it correctly
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900