首页 新闻 会员 周边 捐助

WPF 绑定的问题

0
[待解决问题]
 1  <ItemsControl Grid.Row="1" x:Name="PMItmsControl" VerticalAlignment="Top" ItemsSource="{Binding FirstEntity}">
 2             <ItemsControl.ItemsPanel>
 3                 <ItemsPanelTemplate>
 4                     <VirtualizingStackPanel Orientation="Vertical"/>
 5                 </ItemsPanelTemplate>
 6             </ItemsControl.ItemsPanel>
 7             <ItemsControl.ItemTemplate>
 8                 <DataTemplate>
 9                     <Border CornerRadius="5" BorderBrush="YellowGreen" BorderThickness="1" Margin="5">
10                         <Grid Width="auto" Height="100" VerticalAlignment="Top">
11                             <Grid.RowDefinitions>
12                                 <RowDefinition/>
13                             </Grid.RowDefinitions>
14                             <Grid.ColumnDefinitions>
15                                 <ColumnDefinition Width="60*"/>
16                                 <ColumnDefinition Width="40*"/>
17                             </Grid.ColumnDefinitions>
18                             <TextBlock Width="100" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10" Text="{Binding FirstName}" FontSize="10" >
19                             </TextBlock>
20                             <ItemsControl ItemsSource="{Binding SecondEntity}" Grid.Column="1" VerticalAlignment="Top">
21                                 <ItemsControl.ItemsPanel>
22                                     <ItemsPanelTemplate>
23                                         <VirtualizingStackPanel Orientation="Vertical"/>
24                                     </ItemsPanelTemplate>
25                                 </ItemsControl.ItemsPanel>
26                                 <ItemsControl.ItemTemplate>
27                                     <DataTemplate>
28                                         <Grid>
29                                             <Grid.ColumnDefinitions>
30                                                 <ColumnDefinition Width="50*"/>
31                                                 <ColumnDefinition Width="50*"/>
32                                             </Grid.ColumnDefinitions>
33                                             <TextBlock Text="{Binding SecondName}" Margin="5"  Foreground="White" />
34                                             <TextBlock Grid.Column="1" Text="{Binding Path= DataContext.FirstName, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ItemsControl},AncestorLevel=2}}" Margin="5" Width="40">
35                                             </TextBlock>
36                                         </Grid>
37                                     </DataTemplate>
38                                 </ItemsControl.ItemTemplate>
39                             </ItemsControl>
40                         </Grid>
41                     </Border>
42                 </DataTemplate>
43             </ItemsControl.ItemTemplate>
44         </ItemsControl>

 public class FirstEntity 
    {
        public string FirstName { get; set; }
        public SecondEntity SecondEntity { get; set; }
    }

    public class SecondEntity
    {
        public string SecondName { get; set; }
    }

为什么在第二个ItemsControl里面绑定第一个ItemsControl里的FirstName不行,应该怎么绑定呢?
 
RR幻影的主页 RR幻影 | 初学一级 | 园豆:112
提问于:2017-06-29 12:58
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册