WPF WrapPanel 奇怪的内部缩进
我有 WPF WrapPanel,里面有一个工具栏。 WrapPanel 为红色,工具栏为蓝色。
谁能解释一下,顶部、左侧等处的 WrapPanel 缩进是从哪里来的,以及如何进行的我可以删除它吗?
这是图像的示例代码:
<WrapPanel Orientation="Horizontal" Background="Red">
<ToolBar x:Name="tFirst" Background="Blue" ToolBarTray.IsLocked="True">
<Button ToolTip="New" Content="New" />
<Button ToolTip="Save" Content="Save" />
<Button ToolTip="Delete" Content="Delete" />
</ToolBar>
</WrapPanel>
提前致谢。
更新:问题仅与工具栏有关,我刚刚将 WrapPanel 更改为 DockPanel,问题仍然存在。
I have WPF WrapPanel, and a toolbar inside. The WrapPanel is red and the toolbar is blue.
Could anybody explain me, where did indent of WrapPanel on the top, left etc. come from, and how I can remove it?
Here is the sample code of the image:
<WrapPanel Orientation="Horizontal" Background="Red">
<ToolBar x:Name="tFirst" Background="Blue" ToolBarTray.IsLocked="True">
<Button ToolTip="New" Content="New" />
<Button ToolTip="Save" Content="Save" />
<Button ToolTip="Delete" Content="Delete" />
</ToolBar>
</WrapPanel>
Thanks in advance.
UPDATE: the problem is only with Toolbar, I just changed WrapPanel to DockPanel, and the problem is still exists.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能与
ToolBar
控件的默认内置控件模板有关。显然,一个快速解决方法是将
Margin
设置为 -2。ToolBar
内部相当复杂,它由Grid
、Border
、DockPanel
等组成,你可以尝试一下并使用 VisualTreeHelper 遍历它。例如:检索
DockPanel
对象。您可以尝试找到Margin
或Padding
大于 0 的控件,如果成功,您甚至可以从代码中重置它(例如:(dockPanel as DockPanel).Margin = 0;
)在 XAML 中,我会尝试覆盖
ToolBar 的
控件模板(如 http://msdn.microsoft.com/en-us/ library/aa970772(v=vs.85).aspx - 尽管这个示例对于您的目的来说当然过于复杂,但原理是相同的)。It's probably something about the default, built-in control template of the
ToolBar
control.A quick fix is, obviously, to set
Margin
to -2 for example.ToolBar
is internally quite complex, it consists of aGrid
, aBorder
, aDockPanel
etc. you can try and traverse it withVisualTreeHelper
. For example:retrieves the
DockPanel
object. You can try and find the control withMargin
orPadding
greater than 0, and if you succeed you could probably even reset it from code (something like:(dockPanel as DockPanel).Margin = 0;
)In XAML, I'd try overriding
ToolBar's
control template (as demonstrated in http://msdn.microsoft.com/en-us/library/aa970772(v=vs.85).aspx - although this example is of course overly complex for your purpose, the principle is the same).