3
是否有任何方法将列表按钮动态绑定到WrapPanel
以及它们的事件?从列表中填充WrapPanel
是否有任何方法将列表按钮动态绑定到WrapPanel
以及它们的事件?从列表中填充WrapPanel
我也不太清楚,如果这是你想要做什么是正确的,但它听起来很相似:
从链接的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>
我敢肯定,我展示我的无知在这里(初学者到WPF和XAML的时刻),但我不能看到的ItemsControl如何找到该属性的ItemsSource(我相信是在源文章中提到)。 – tobriand 2014-10-16 15:14:04
我是个白痴。对于任何对WPF不熟悉的人,为了避免混淆,ItemsControl有一个属性(ItemsSource),可以在运行时分配,而不是通过关联VM上的属性。据推测,这也意味着添加属性'ItemsSource =“{Binding MyList}”'可能会工作... – tobriand 2014-10-16 15:17:32