【问题标题】:Windows Phone 8.1 flow container for dynamic buttons用于动态按钮的 Windows Phone 8.1 流容器
【发布时间】:2015-08-18 23:14:38
【问题描述】:

SOF 部落,

我有一个流容器的标识请求,我可以将不确定数量的动态创建的 XAML 按钮倒入其中。所述按钮应尽可能紧密地包裹文本(我想我有一个模板)。但是按钮应该像 gridview 一样包装,但像 stackpanel 一样运行。有谁知道一个容器可以让我完成图像所描绘的内容?

目前,对于下面的现有图像,我使用的是 gridview,但 gridview 设置了特定的宽度,但流动不均匀。 stackpanel 具有所需的端对端样式,但不会换行。那么,有什么想法吗?

【问题讨论】:

    标签: c# asp.net xaml gridview


    【解决方案1】:

    Greg Stoll 制造了所谓的 UniversalWrapPanel。所以,这就是我要走的方向。然而,现在,我有最后一点需要解决。如何获取绑定数据以尊重父容器包装内容的能力,而不仅仅是将其堆叠在垂直列中。

    下面的 XAML 给了我下面的图像结果,这不是我想要的。静态添加的按钮适用于 UniversalWrapPanel。但试图让绑定和 ItemsSource 工作,好吧,目前这超出了我的范围。

    <support:UniversalWrapPanel  Orientation="Horizontal" Background="White">
        <ItemsControl x:Name="GridViewRecipients" ItemsSource="{Binding}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Style="{StaticResource ButtonLozengeStyle}" Content="{Binding FullName}"/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </support:UniversalWrapPanel>
    

    好的,所以再搜索一下,我发现了这个:

    http://www.visuallylocated.com/post/2015/02/20/Creating-a-WrapPanel-for-your-Windows-Runtime-apps.aspx

    所以这是在 ItemsControl 中引用 UniversalWrapPanel 的正确方法:

    <ItemsControl x:Name="GridViewRecipients" ItemsSource="{Binding}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <support:UniversalWrapPanel Orientation="Horizontal" Background="DodgerBlue"/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Button Style="{StaticResource ButtonLozengeStyle}" Content="{Binding FullName}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    

    对于结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多