1

I have a ListView that gets populated dyanmically by items that consist of a grid that holds an image and a button like this:

<ListView  x:Name="Thumbnails" HorizontalContentAlignment ="Left" VerticalContentAlignment="Top" Padding="0"  Background ="#81AFD3" Grid.Row="6" Grid.Column="6" Grid.ColumnSpan="10" Grid.RowSpan="27" ScrollViewer.VerticalScrollBarVisibility="Visible" ItemsSource="{Binding ThumbModelList}" SelectedIndex="{Binding SelectedIndx}">
  <ListView.ItemTemplate>
                    <DataTemplate>
                        <ListViewItem>

                            <Grid Width="{Binding DataContext.ThumbnailWidth, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}" Height="{Binding DataContext.ThumbnailHeight, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}" HorizontalAlignment="Center" VerticalAlignment="Top" Background="Transparent" >

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="1*" />
                                    <RowDefinition Height="1*" />
                                    <RowDefinition Height="1*" />
                                    <RowDefinition Height="1*" />
                                    <RowDefinition Height="1*" />
                                    <RowDefinition Height="1*" />
                                    <RowDefinition Height="1*" />
                                </Grid.RowDefinitions>

                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                    <ColumnDefinition Width="1*" />
                                </Grid.ColumnDefinitions>

                                <Image Name="thumbImage" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="14" Grid.RowSpan="7" Stretch="UniformToFill" Source="{Binding MainThumbImagePath}"></Image>

                                 <Button Name="slide_ON_OFF" Grid.Row="0" Grid.Column="10" Grid.ColumnSpan="4" Grid.RowSpan="4" VerticalAlignment="Center" Background="Transparent" Command="{Binding DataContext.SlideOnOffCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}">
                                    <Image Source="{Binding SomePath}"/>
                                </Button>

                            </Grid>
                        </ListViewItem>
                    </DataTemplate>
                </ListView.ItemTemplate>

            </ListView>


        now, once the list is populated dynamically with those items, at certain positions, I want to insert a diffrerent item that has three different buttons like this:

     <Grid Width="{Binding DataContext.ThumbnailWidth, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}" Height="{Binding DataContext.ThumbnailHeight, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}" HorizontalAlignment="Center" VerticalAlignment="Top" Background="Transparent" >

                        <Grid.RowDefinitions>
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="1*" />
                            <RowDefinition Height="1*" />
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="1*" />
                        </Grid.ColumnDefinitions>


                         <Button Name="slide_ON_OFF" Grid.Row="0" Grid.Column="10" Grid.ColumnSpan="4" Grid.RowSpan="4" VerticalAlignment="Center" Background="Transparent" Command="{Binding DataContext.Command1, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}"/>
                         <Button Name="slide_ON_OFF" Grid.Row="0" Grid.Column="10" Grid.ColumnSpan="4" Grid.RowSpan="4" VerticalAlignment="Center" Background="Transparent" Command="{Binding DataContext.Command2, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}"/>
                         <Button Name="slide_ON_OFF" Grid.Row="0" Grid.Column="10" Grid.ColumnSpan="4" Grid.RowSpan="4" VerticalAlignment="Center" Background="Transparent" Command="{Binding DataContext.Command3, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}"/>
     </Grid> 

Is this possible to do, and where and how to declare this other list item in XAML?

Ivan
  • 1,081
  • 2
  • 17
  • 43
  • 1
    you should use a data template for each data type – ZSH May 24 '16 at 08:15
  • Ok, but how is it going to know which data type to populate initially? I first want the list to get populated trough a loop by 'DataType1' and then after that I want to manually insert 'Datatype2' on some user action. – Ivan May 24 '16 at 08:21
  • 1
    ThumbModelList type should be a base type list for itemtype1 and itemtype2 (for example ObserbableCollection), now when you add a type1 or type2 item it has the corresponding datatemplate as in my example in the answer below – ZSH May 24 '16 at 08:22

1 Answers1

1

you can use datatemplates via data type or template selector ,here is an example for data type: Example

this is a simple one, it also depends on your data / Datacontext

Community
  • 1
  • 1
ZSH
  • 905
  • 5
  • 15