包裹面板未包裹数据项

发布于 2024-11-27 23:55:24 字数 1183 浏览 2 评论 0原文

我有 WrapPanel,我希望其中的控件水平且居中,但是当我有列表框或 ItemsControl 时,这些元素只会向下。

<toolkit:WrapPanel>

    <ItemsControl x:Name="AnswerListBox" ItemsSource="{Binding Answers}" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <!-- those don't wrap horizontally and go downwards -->
                <local:spriteToggleButton Text="{Binding text}" Selected="{Binding selected}" Sprites="{Binding Path=DataContext.UISprites, ElementName=questionField}" IsChecked="{Binding selected, Mode=TwoWay}" GroupName="{Binding Path=DataContext.QuestionTitle, ElementName=questionField}" ClickMode="Press" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

</toolkit:WrapPanel>

我遇到了一些类似的问题,并发现了 ItemsPanel,所以我尝试了,但它只换行到内容,并且没有显示其中的其余控件。

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <toolkit:WrapPanel />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

我认为 ItemsPanel 告诉 ItemsControl 用哪个控件来包装它,但它似乎忽略了我的数据模板的其余部分。

I have WrapPanel where I want the control inside of it to go horizontally and centered, but when I have a listbox or a ItemsControl those elements just go downwards.

<toolkit:WrapPanel>

    <ItemsControl x:Name="AnswerListBox" ItemsSource="{Binding Answers}" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <!-- those don't wrap horizontally and go downwards -->
                <local:spriteToggleButton Text="{Binding text}" Selected="{Binding selected}" Sprites="{Binding Path=DataContext.UISprites, ElementName=questionField}" IsChecked="{Binding selected, Mode=TwoWay}" GroupName="{Binding Path=DataContext.QuestionTitle, ElementName=questionField}" ClickMode="Press" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

</toolkit:WrapPanel>

I came across some similar issues and found out about ItemsPanel, so I tried that but it wrap but only to Content and didn't display the rest of the control inside of it.

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <toolkit:WrapPanel />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

I take it that ItemsPanel is telling the ItemsControl which control to wrap it with but then it seems to ignore the rest of my datatemplate.

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

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

发布评论

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

评论(1

小红帽 2024-12-04 23:55:24

约瑟夫,

这里是在黑暗中拍摄的;但这就是我使用 WrapPanel 的方式(不是通过 ItemControl)。

<ListBox> 
   <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
             <toolkit:WrapPanel Width="700" />
        </ItemsPanelTemplate>
   </ListBox.ItemsPanel>
   <ListBox.ItemTemplate>
         <DataTemplate>
         ....
         </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>

本质上,列表框的 ItemsPanel 告诉它使用 WrapPanel,然后您就可以在 DataTemplate 中获得所需的任何内容。请注意,宽度很重要,因为它告诉 WrapPanel 从哪里开始换行。

这有帮助吗?

Joseph,

Slightly shooting in the dark here; but this is how I have used the WrapPanel (not through the ItemControl).

<ListBox> 
   <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
             <toolkit:WrapPanel Width="700" />
        </ItemsPanelTemplate>
   </ListBox.ItemsPanel>
   <ListBox.ItemTemplate>
         <DataTemplate>
         ....
         </DataTemplate>
   </ListBox.ItemTemplate>
</ListBox>

Essentially the Listbox's ItemsPanel tells it to use the WrapPanel and then you could have anything you need in the DataTemplate. Note that the width is important as it tells the WrapPanel where to start wrapping.

Does this help?

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