2010-12-10 39 views
1

语法问题我使用Silverlight 4,下面的XAML正常工作:的Silverlight:用于设置值

<UserControl.Resources> 
    <ItemsPanelTemplate x:Key="WrapPanelTemplate"> 
     <toolkit:WrapPanel /> 
    </ItemsPanelTemplate> 
</UserControl.Resources> 

    <ItemsControl x:Name="restOfHits" 
        ItemsSource="{Binding RestOfHits}" 
        ItemsPanel="{StaticResource WrapPanelTemplate}" 
        ItemTemplate="{StaticResource FileTemplate}" 
        Width="500" 
        Margin="0,50,0,0" 
        /> 

但是,由于以下原因VS抱怨:

<ItemsControl x:Name="restOfHits" 
        ItemsSource="{Binding RestOfHits}" 
        ItemTemplate="{StaticResource FileTemplate}" 
        Width="500" 
        Margin="0,50,0,0" 
        > 
     <ItemsControl.ItemsPanel> 
      <toolkit:WrapPanel /> 
     </ItemsControl.ItemsPanel> 
    </ItemsControl> 

错误:

Property 'ItemsPanel' does not support values of type 'WrapPanel'.

这是为什么?如果我不想使用资源,指定ItemsControl应该使用WrapPanel的正确方法是什么?

回答

2

因为ItemsPanel期望收到ItemsPanelTemplate而不是其他任何东西。 你在你的第一个样本中这样做,但不是在你的第二个样本中。你的第二个应该看起来像这样: -

<ItemsControl x:Name="restOfHits" 
       ItemsSource="{Binding RestOfHits}" 
       ItemTemplate="{StaticResource FileTemplate}" 
       Width="500" 
       Margin="0,50,0,0" 
       > 
    <ItemsControl.ItemsPanel> 
     <ItemsPanelTemplate> 
      <toolkit:WrapPanel /> 
     </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl>