有没有办法动态地将列表按钮绑定到WrapPanel以及它们的事件? 我不太确定这对你想要做的事情是否正确,但听起来非常相似: WPF – Fill a WrapPanel from a List 上面链接中的XAML如下: ItemsC
> WPF – Fill a WrapPanel from a List
上面链接中的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>