首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tabcontrol contentTemplate定位

Tabcontrol contentTemplate定位
EN

Stack Overflow用户
提问于 2012-01-04 21:47:58
回答 1查看 1K关注 0票数 0

祝大家新年快乐!感谢你阅读这篇文章!

我在为contentTemplate定位动态内容时遇到了问题,我有以下几点:

代码语言:javascript
复制
<TabControl ItemsSource="{Binding Cats}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}" FontSize="16" FontWeight="Bold"></TextBlock>
                </DataTemplate>                
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <WrapPanel>
                        <ItemsControl ItemsSource="{Binding Products}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Button Content="{Binding Name}" Height="25" Width="100"></Button>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </WrapPanel>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>

itemsSource绑定猫返回一个类别列表,并且在每个类别中都有一个属性返回产品列表

目前正在显示所有垂直堆叠的按钮,但我需要的按钮来填充wrapPanel。下面是我要找的contentTemplate的图示:

任何想法都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-04 22:07:10

您需要使用WrapPanel作为ItemsPanel模板。有关参考,请参阅this问题。基本上,您需要将此XAML添加到:

代码语言:javascript
复制
<ItemsControl ItemsSource="{Binding Products}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button Content="{Binding Name}" Height="25" Width="100"></Button>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

注意:您实际上不需要设置WrapPanelOrientation属性,它只是为了显式。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8727962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档