2010-03-01 103 views

回答

7

我也不太清楚,如果這是你想要做什麼是正確的,但它聽起來很相似:

從鏈接的XAML上面是如下:

<ItemsControl x:Name="activitiesControl" Margin="10"> 
    <ItemsControl.Template> 
     <ControlTemplate> 
      <WrapPanel Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" 
        FlowDirection="LeftToRight" IsItemsHost="true"> 
      </WrapPanel> 
     </ControlTemplate> 
    </ItemsControl.Template> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <Button Style="{DynamicResource ActionButton}" HorizontalAlignment="Right" Margin="5" 
       Content="{Binding Value}" Width="200" 
       Command="{Binding Path=ViewModel.ActionTypeCommand, 
        RelativeSource={RelativeSource Mode=FindAncestor,  
       AncestorType=local:CustomerEditView}}" CommandParameter="{Binding Key}"/> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
</ItemsControl> 
+0

我敢肯定,我展示我的無知在這裏(初學者到WPF和XAML的時刻),但我不能看到的ItemsControl如何找到該屬性的ItemsSource(我相信是在源文章中提到)。 – tobriand 2014-10-16 15:14:04

+2

我是個白癡。對於任何對WPF不熟悉的人,爲了避免混淆,ItemsControl有一個屬性(ItemsSource),可以在運行時分配,而不是通過關聯VM上的屬性。據推測,這也意味着添加屬性'ItemsSource =「{Binding MyList}」'可能會工作... – tobriand 2014-10-16 15:17:32