我通过MSDN的代码来深入了解MVVC,但是我有一个问题。
.xaml文件中有一份命令列表显示在屏幕上。
<Border
Grid.Column="0"
Style="{StaticResource MainBorderStyle}"
Width="170"
>
<HeaderedContentControl
Content="{Binding Path=Commands}"
ContentTemplate="{StaticResource CommandsTemplate}"
Header="Control Panel"
Style="{StaticResource MainHCCStyle}"
/>
</Border>
从这里我可以理解到DataContext已经被设置(此处未显示),并且它将显示命令集合。但是我不理解下面可以看到的CommandsTemplate:
<DataTemplate x:Key="CommandsTemplate">
<ItemsControl IsTabStop="False" ItemsSource="{Binding}" Margin="6,2">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Margin="2,6">pou
<Hyperlink Command="{Binding Path=Command}">
<TextBlock Text="{Binding Path=DisplayName}" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
绑定是如何创建的?这段代码是如何告诉程序从集合中检查属性Command和DisplayName的?它是从ItemsSource中获取的吗?如果是,为什么只有在{Binding}处出现?有人可以解释一下ContentTemplate中的DataTemplate绑定是如何工作的吗?