白开水易拉罐 发表于 2013-1-3 15:35:42

WPF中使用ItemsControl嵌套绑定,在ItemsControl中嵌套一个ItemsControl,然后使用绑定

<div id="cnblogs_post_body">最需要注意的一点是,绑定一定要使用属性,因为属性提供{set;get;}方法。
XAML中的定义:
注意:需要在第二层ItemsControl的ItemsSource绑定的内容
<div class="cnblogs_code"><Window x:Class="Binding_Demo_01.MainWindow"      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      Title="MainWindow" Height="350" Width="525">    <Grid>      <ItemsControl x:Name="list1">            <ItemsControl.ItemsPanel>                <ItemsPanelTemplate>                  <StackPanel Orientation="Horizontal" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Center"/>                </ItemsPanelTemplate>            </ItemsControl.ItemsPanel>            <ItemsControl.ItemTemplate>                <DataTemplate>                  <ItemsControl ItemsSource="{Binding CurrPerson}" MouseDoubleClick="ItemsControl_MouseDoubleClick">                        <ItemsControl.ItemsPanel>                            <ItemsPanelTemplate>                              <StackPanel Orientation="Horizontal" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Center"/>                            </ItemsPanelTemplate>                        </ItemsControl.ItemsPanel>                        <ItemsControl.ItemTemplate>                            <DataTemplate>                              <StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center">                                    <Image Source="{Binding Image}" Stretch="UniformToFill" Height="400" Width="230" Margin="4"/>                                    <TextBlock Text="{Binding Name}" Margin="4"/>                              </StackPanel>                            </DataTemplate>                         </ItemsControl.ItemTemplate>                  </ItemsControl>                </DataTemplate>            </ItemsControl.ItemTemplate>      </ItemsControl>    </Grid></Window>
页: [1]
查看完整版本: WPF中使用ItemsControl嵌套绑定,在ItemsControl中嵌套一个ItemsControl,然后使用绑定