c# - 从列表中填充 WrapPanel

标签 c# wpf xaml binding wrappanel

有没有办法将列表按钮动态绑定(bind)到 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>

关于c# - 从列表中填充 WrapPanel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2354516/

相关文章:

c# - 最佳实践 : Convert LINQ Query result to a DataTable without looping

c# - 成对索取元素最直观的方式是什么?

c# - 从 FrameworkElementFactory 获取值

xaml - CalendarDatePicker 在第二次选择相同的日期时返回 null

c# - 三角函数 sin C# Cos & Cos A

c# - 发布参数始终为空

wpf - 测试驱动开发 - WPF

.net - 哪些代码控制 WPF 应用程序的启动?

c# - 使用来自另一个 UserControl 的 MVVM 启用/禁用按钮

c# - 预览MouseMove 与 MouseMove