从列表中填充 WrapPanel

发布于 2024-08-23 03:32:05 字数 51 浏览 3 评论 0原文

有没有办法将列表按钮动态绑定到 WrapPanel 及其事件?

Is there any way of dynamically binding a list buttons to a WrapPanel as well as their events?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏の忆 2024-08-30 03:32:05

我不太确定这是否适合您想要做的事情,但听起来非常相似:

上面链接中的 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>

I'm not too sure if this is correct for what you are wanting to do, but it sounds very similar:

The XAML from the link above is as follows:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文