c# - 在 wpf 的 tabpanel 中添加新按钮(添加按钮)时,TabControl 边框不隐藏
问题描述
在选项卡控件中,我必须将 + 按钮添加到选项卡项,如屏幕截图所示。我在选项卡面板中添加了加号按钮,当我运行程序并选择选项卡项时,选项卡控件边框不会像普通选项卡控件那样隐藏。为了清楚我的问题,请检查随附的屏幕截图。
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid
x:Name="templateRoot"
ClipToBounds="true"
KeyboardNavigation.TabNavigation="Local"
SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0" />
<ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto" />
<RowDefinition x:Name="RowDefinition1" Height="*" />
</Grid.RowDefinitions>
<StackPanel
x:Name="headerPanel"
Grid.Row="0"
Grid.Column="0"
Orientation="Horizontal">
<TabPanel
x:Name="_HeaderPanel"
Panel.ZIndex="1"
IsItemsHost="true"
KeyboardNavigation.TabIndex="1" />
<Button
x:Name="addButton"
Width="50"
Height="30"
Background="LightGray"
BorderBrush="LightGray"
BorderThickness="1,0,0,0"
Command="{Binding ChartAddButton_Click}"
Content="+" />
</StackPanel>
<Border
x:Name="contentPanel"
Grid.Row="1"
Grid.Column="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2"
KeyboardNavigation.TabNavigation="Local">
<ContentPresenter
x:Name="PART_SelectedContentHost"
Margin="{TemplateBinding Padding}"
ContentSource="SelectedContent"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</Grid>
通过将加号按钮添加到选项卡面板,这将发生。如何解决这个问题。请给出你的建议。
解决方案
我假设您指的是虚线。那不是正在显示的边框,我认为这是FocusVisualStyle
按钮的默认设置。
尝试设置,
FocusVisualStyle = "{x:null}"
按钮上。
推荐阅读
- python - 与异步请求一起执行函数
- docker - 如何在 docker 容器中连接到 Cassandra 以便在主机上查看 DBVisualize?
- typescript - 使用 Typescript watcher Compiler API 检测成功/失败
- amazon-web-services - 图像上传 s3 存储桶表单部署的 dot net cor AWS lambda 无服务器应用程序不工作(损坏的图像)
- java - 如何在 Spring 测试中创建嵌入式 Kafka 时修复“无效 URL”
- jquery - 将多部分文本文件作为 url 参数发送
- safari - p5.js Safari play() pause() jump() 问题
- json - 如何解析此 JSON 以获取呈现的标题?
- ruby-on-rails - 如何对多态属性进行 rspec 测试验证?
- c# - 如何将跑步和动画添加到我的播放器控制器脚本?