【问题标题】:Tabcontrol contentTemplate positioning选项卡控件内容模板定位
【发布时间】:2012-01-04 13:47:58
【问题描述】:

祝大家新年快乐!感谢您阅读本文!

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

<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 的插图:

任何想法将不胜感激!

【问题讨论】:

    标签: wpf vb.net binding tabcontrol itemtemplate


    【解决方案1】:

    您需要使用WrapPanel 作为ItemsPanel 模板。请参阅this 问题以供参考。基本上,您需要在以下位置添加此 XAML:

    <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 属性,只是为了明确起见。

    【讨论】:

    • 该死的应该已经意识到 wrappanel 去了那里。非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多