创建选项卡式侧边栏与部分WPF [英] Create Tabbed Sidebar with sections WPF

查看:2596
本文介绍了创建选项卡式侧边栏与部分WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个标签栏与部分,就像在WPF以下。有迹象表明,我已经考虑了几个方案,但有一个更简单,更优雅的方式来做到这一点?

I'm trying to create a tabbed sidebar with sections, like the following in WPF. There are a few approaches that I have considered, but is there a simpler and more elegant way to do it?

方法1:列表框

使用列表框和绑定的SelectedItem的值,其中右边的内容控件绑定到。到标题和章节区分,我使用一个DataTemplate选择

Using a ListBox and binding SelectedItem to a value, which the content control on the right binds to. To differentiate between the header and the sections, I use a DataTemplate selector.

方法2:单选按钮/检查箱/的ToggleButtons

使用单选按钮,我所选择的项目绑定到内容的控制。然而,由于WPF的错误,我会使用值转换器将它们连接在一起。

Using radiobuttons, I bind the selected item to the content control. However, due to the WPF bug, I will have to link them together using value converters.

推荐答案

添加多一点的造型到这一点,我认为它可以工作pretty的好

Add a little more styling to this and I think it could work pretty well

    <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>

这篇关于创建选项卡式侧边栏与部分WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆