使用WPF部分创建选项卡式边栏

时间:2011-05-16 08:31:25

标签: c# .net wpf user-controls controls

我正在尝试使用部分创建带标签的侧边栏,如WPF中的以下内容。我考虑过一些方法,但有更简单,更优雅的方法吗?

方法1:ListBox

使用ListBox并将SelectedItem绑定到一个值,右边的内容控件绑定到该值。为了区分标题和部分,我使用了DataTemplate选择器。


方法2:RadioBUtton / Check Boxes / ToggleButtons

使用单选按钮,我将所选项目绑定到内容控件。但是,由于WPF错误,我将不得不使用值转换器将它们链接在一起。


Tabbed Interface Split into Sections

enter image description here

2 个答案:

答案 0 :(得分:2)

为此添加更多样式,我认为它可以很好地运作

    <TabControl TabStripPlacement="Left">
        <TabControl.Resources>
            <Style TargetType="TabItem" x:Key="SideBarSectionStyle">
                <Setter Property="IsEnabled" Value="False" />
                <Setter Property="FontSize" Value="16" />
                <Setter Property="Foreground" Value="LightGreen" />
            </Style>
        </TabControl.Resources>

        <TabItem Header="Section A" Style="{StaticResource SideBarSectionStyle}" />
        <TabItem Header="Tab Item 1" IsSelected="True" />
        <TabItem Header="Tab Item 2" />
        <TabItem Header="Tab Item 3" />
        <TabItem Header="Tab Item 4" />
        <TabItem Header="Tab Item 5" />
        <TabItem Header="Section B" Style="{StaticResource SideBarSectionStyle}" />
        <TabItem Header="Tab Item 6" />
        <TabItem Header="Tab Item 7" />
        <TabItem Header="Tab Item 8" />
        <TabItem Header="Tab Item 9" />
    </TabControl>

答案 1 :(得分:1)

以下是一些更多的想法:

  1. (可能是最理想的)使用树视图并模板父母和孩子隐藏展开按钮。 This应该帮助您弄清楚如何隐藏它们。

  2. 不使用1个列表框,而是使用多个列表框,每个列表框代表不同类别的选项。如果需要,您可以使用相同的模板或不同的模板。此外,我会将标题保留在列表框之外,并使其成为标签或位于列表视图上方的任何内容。您可以调整列表框中的边距以获得树视图中的父/子缩进。