简体   繁体   中英

Change ItemSource on a ItemsControl inside a DataTemplate

On windows phone 8, i have a page that has the following XAML

<ScrollViewer Grid.Row="1">
        <ItemsControl Name="Items1" >
            <ItemsControl.ItemTemplate>
                <DataTemplate x:Name="DataTemp">
                    <Grid Margin="0,10,0,0" Height="380">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="3*"/>
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding img.path}" VerticalAlignment="Top" Margin="10,0" />
                        <ScrollViewer Name="Vinhos" Grid.Column="1" Background="#7FE00E0E" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
                            <ItemsControl x:Name="Items2">
                                <Image Source="img.png" Height="400" />
                            </ItemsControl>
                        </ScrollViewer>
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </ScrollViewer>

I set the ItemsSource of the first ItemsControl with a list of objects of this type

        public class Familia
        {
         public string nome { get; set; }
         public Imagem img { get; set; }
         public List<Produto> listaProdutos { get; set; }
        }

Like so, Items1.ItemsSource = fams.listaFamilias;

What i want to do is to get the ItemsSource of the second ItemsControl, named "Items2" with the List from the object that is being used in the first ItemsControl named "Items1"

试试下面的Items2声明:

<ItemsControl x:Name="Items2" ItemsSource="{Binding ItemsSource, ElementName=Items1}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM