【问题标题】:WPF TabControl remove header padding?WPF TabControl删除标题填充?
【发布时间】:2013-02-22 07:19:14
【问题描述】:

我正在尝试这样做,以便在用户单击我的 TabControl 中的 TabItem 标题时执行命令。

这是我的代码:

      <TabControl TabStripPlacement="Left" BorderThickness="1,0,0,0">
        <TabItem Selector.IsSelected="{Binding IsGeneric, Mode=OneWay}">
            <TabItem.Header>
                <Button Content="Generic" Margin="0" Command="{Binding GenericSelected}"></Button>
            </TabItem.Header>
            <V:WasteEstimationGenericView DataContext="{Binding}"></V:WasteEstimationGenericView>
        </TabItem>
        <TabItem Selector.IsSelected="{Binding IsSTP, Mode=OneWay}">
            <TabItem.Header>
                <Button Content="STP" Margin="0" Command="{Binding STPSelected}"></Button>
            </TabItem.Header>
            <V:WasteEstimationSTPView DataContext="{Binding STPViewModel}"></V:WasteEstimationSTPView>
        </TabItem>
    </TabControl>

但是我最终得到的结果是这样的:

谁能告诉我如何让我的 TabControl 标头占用 TabItem 标头中的所有可用空间?我最初想使用标签来执行此操作,但它有一个问题,如果用户单击标题的边缘它不会执行命令,我仍然更喜欢使用按钮,但是按钮允许用户定位到哪里他们点击。

【问题讨论】:

    标签: c# wpf xaml .net-4.0 tabcontrol


    【解决方案1】:

    您需要修改TabItem ControlTemplate,更具体地说是ContentPresenter,将VerticalAlignmentHorizontalAlignment 设置为Stretch,并将Margin 设置为您想要的,默认为12,2 ,12,2.

    【讨论】:

      【解决方案2】:

      试试这个:

      <TabControl TabStripPlacement="Left" BorderThickness="1,0,0,0" HorizontalContentAlignment="Stretch">
      

      【讨论】:

      • 我根据您的代码创建了一个测试项目,减去视图绑定和拉伸 STP 按钮宽度以满足通用按钮宽度。您是否能够创建一个新窗口并仅使用 TabControl 进行测试?我怀疑 TabControl 的父容器导致了您的问题。
      • 隔离那个控件需要做很多工作,但我不是在寻找相同长度的按钮,我正在寻找它们来填充可用空间等。同时设置水平内容对齐选项卡控件上的似乎没有改变按钮尺寸。
      猜你喜欢
      • 1970-01-01
      • 2021-06-09
      • 1970-01-01
      • 2012-09-07
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 2014-04-20
      相关资源
      最近更新 更多