none
ListBox dentro de ListBox RRS feed

  • Pergunta

  • Tenho um listbox preenchido por binding de uma coleção, onde os itens são expanders, dentro dos expanders gostaria de ter outro listbox que faça o binding de uma coleção diferente, isso é possivel?

    Obrigado.

    terça-feira, 18 de janeiro de 2011 11:11

Respostas

  • o codigo abaixo possui 2 listbox no expander,
    faça o binding de uma coleção diferente no ItemSource.

     

    <Expander.Content>
    <StackPanel Width="100" Height="100" Background="White">
                                                <ListBox ItemsSource="{Binding Roadmaps}"
                                             BorderThickness="0" Margin="0,0,0,5"
                                             Name="lbModelsReport" Height="10" >
                                                    <ItemsControl.ItemTemplate>
                                                       <DataTemplate>
                                                            <StackPanel  Orientation="Vertical" Width="90"
                                                            VerticalAlignment="Center">
                                                                <CheckBox Content="{Binding Path=Name}"/>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ItemsControl.ItemTemplate>
                                                </ListBox>
                                                <ListBox ItemsSource="{Binding Roadmaps}"
                                                    BorderThickness="0" Margin="0,0,0,5"
                                                    x:Name="lbModelsReport2" Height="10" >
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <StackPanel  Orientation="Vertical" Width="90"
                                                                VerticalAlignment="Center">
                                                                <CheckBox Content="{Binding Name}"/>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox>
                                            </StackPanel>
    </Expander.Content>

     

    Rafael.

    terça-feira, 18 de janeiro de 2011 13:52

Todas as Respostas

  • ola diego

    listbox dentro de expanders

    <Grid x:Name="LayoutRoot">
           
            <ListBox x:Name="listbox1" Margin="23.5,23,0,0" HorizontalAlignment="Left" Height="156.334" VerticalAlignment="Top" Width="202.333">
                <Expander x:Name="exp1" Header="Expander 1" Height="39" Width="175">
                    <Grid Background="#FFE5E5E5">
                        <ListBox x:Name="listbox2"/>
                    </Grid>
                </Expander>
                <Expander x:Name="exp2" Header="Expander 2" Height="39" Width="175">
                    <Grid Background="#FFE5E5E5">
                        <ListBox x:Name="listbox3"/>
                    </Grid>
                </Expander>
                <Expander x:Name="exp3" Header="Expander 3" Height="39" Width="175">
                    <Grid Background="#FFE5E5E5">
                        <ListBox x:Name="listbox4"/>
                    </Grid>
                </Expander>
                <Expander x:Name="exp4" Header="Expander 4" Height="39" Width="175">
                    <Grid Background="#FFE5E5E5">
                        <ListBox x:Name="listbox5"/>
                    </Grid>
                </Expander>
                <Expander x:Name="exp5" Header="Expander 5" Height="39" Width="175">
                    <Grid Background="#FFE5E5E5"/>
                </Expander>
                <Expander x:Name="exp6" Header="Expander 6" Height="39" Width="175">
                    <Grid Background="#FFE5E5E5"/>
                </Expander>
                <ListBox x:Name="listbox8" Height="72.667" Width="168.833"/>
            </ListBox>
            <ListBox x:Name="listbox9" HorizontalAlignment="Right" Margin="0,196.833,78.5,151.834" Width="200">
                <ListBox x:Name="listbox10" Height="60" Width="100" Margin="45,10,0,0"/>
            </ListBox>
        </Grid>

    cada um com seu x:Name

     

     

    terça-feira, 18 de janeiro de 2011 11:50
  • Então mas o problema é que os expanders são itens de um listbox gerado por binding: segue o código

                        <ListBox ItemsSource="{Binding Models}"
                                 BorderThickness="0" Margin="0,0,0,10"
                                 x:Name="lbModels" BorderBrush="Transparent"
                                 Visibility="Hidden">

                            <ItemsControl.ItemTemplate>
                                <DataTemplate >
                                    <Expander Name="ex" >
                                        <Expander.Header>
                                            <StackPanel >
                                                <Image Height="35" Width="35" Margin="5,0,5,0"
                                                       Source="{Binding Path=Type,
                                                       Converter={StaticResource ImageConverter}}"/>
                                                <StackPanel Orientation="Vertical" Width="100"
                                                            VerticalAlignment="Center">
                                                    <TextBlock Text="{Binding Path=Name}"/>
                                                    <TextBlock Text="{Binding Path=Description}"/>
                                            </StackPanel>
                                        </Expander.Header>

                                        <Expander.Content>
                                            <StackPanel Width="100" Height="100" Background="White">
                                                <ListBox ItemsSource="{Binding Roadmaps}"
                                             BorderThickness="0" Margin="0,0,0,5"
                                             Name="lbModelsReport" >
                                                    <ItemsControl.ItemTemplate>
                                                       <DataTemplate>
                                                            <StackPanel  Orientation="Vertical" Width="90"
                                                            VerticalAlignment="Center">
                                                                <CheckBox Content="{Binding Path=Name}"/>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ItemsControl.ItemTemplate>
                                                </ListBox>
                                            </StackPanel>
                                        </Expander.Content>


                                    </Expander>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ListBox>
    terça-feira, 18 de janeiro de 2011 12:57
  • o codigo abaixo possui 2 listbox no expander,
    faça o binding de uma coleção diferente no ItemSource.

     

    <Expander.Content>
    <StackPanel Width="100" Height="100" Background="White">
                                                <ListBox ItemsSource="{Binding Roadmaps}"
                                             BorderThickness="0" Margin="0,0,0,5"
                                             Name="lbModelsReport" Height="10" >
                                                    <ItemsControl.ItemTemplate>
                                                       <DataTemplate>
                                                            <StackPanel  Orientation="Vertical" Width="90"
                                                            VerticalAlignment="Center">
                                                                <CheckBox Content="{Binding Path=Name}"/>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ItemsControl.ItemTemplate>
                                                </ListBox>
                                                <ListBox ItemsSource="{Binding Roadmaps}"
                                                    BorderThickness="0" Margin="0,0,0,5"
                                                    x:Name="lbModelsReport2" Height="10" >
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <StackPanel  Orientation="Vertical" Width="90"
                                                                VerticalAlignment="Center">
                                                                <CheckBox Content="{Binding Name}"/>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox>
                                            </StackPanel>
    </Expander.Content>

     

    Rafael.

    terça-feira, 18 de janeiro de 2011 13:52
  • A solução que eu encontrei foi adicionar a classe que ira fazer o binding um arraylist e vincular o path para esse array list, ficando assim com listbox de expanders onde cada um contem outro listbox de itens

    ex:

    class Model{

    string Name

    arraylist Exercises;

    }

     

    e na classe que vai fazer o binding uma colecao Models, assim no design

     

      <ListBox ItemsSource="{Binding Models}"

     <ItemsControl.ItemTemplate>
                                <DataTemplate >
                                    <Expander >

                                       <Expander.Header>

                                             <TextBlock Text="{Binding Path=Name, ...}

                                   <Expander.Content>
                                                <ListBox ItemsSource="{Binding Exercises}"
                                             ....

     

    Mas Obrigado pelas respostas

    sexta-feira, 18 de fevereiro de 2011 12:43