为 stackPanel 提供与工具栏默认相同的 LinearGradientBrush
我有两个并排的工具栏(我必须这样做,这样我才能左右对齐按钮) 但现在,我必须添加一些可以在两个工具栏之间右左对齐或居中对齐的文本。我将文本添加到位于第二个位置(工具栏之间)的 Grid
上的 StackPanel
内的 TextBlock
中,当然,它在两个工具栏之间创建了一个间隙(当然,stackPanel 与工具栏的样式不同)。
我想在我的堆栈面板上复制工具栏 LinearGradientBrush
,使其看起来与我的工具栏相同。重点是让这个东西看起来像一个工具栏。
有没有办法获取 ToolBar
Style
或使用 LinearGradientBrush
定义重新创建它,如果可以,如何实现?
I have two ToolBar
s side by side (I had to do that so I could align buttons right and left)
But now, I have to add some text that can be aligned right left or center between both toolbars. I added the text in a TextBlock
inside a StackPanel
disposed on a Grid
at the second position (between the toolbars) and, of course, it created a gap between both toolbars (A stackPanel doesn't have the same style as a toolbar, of course).
I would like to replicate the toolbar LinearGradientBrush
on my stackpanel so it looks the same as my toolbar does. the point is to make the thing look like ONE toolbar.
Is there a way to get the ToolBar
Style
or to recreate it with a LinearGradientBrush
definition, and if so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是您可以做到的一种方法。假设您的工具栏之一的名称是“toolBar”。将
StackPanel
上的Background
属性绑定到ToolBar
上的Background
属性,如下所示:希望有帮助! :)
编辑:
您可以查看
ToolBar
的控件模板 此处。使用的
LinearGradientBrush
看起来如下:如果您只想使用它而不是绑定。 :)
Here's one way you could do it. Say one of your toolbars' name is "toolBar." Bind the
Background
property on theStackPanel
to theBackground
property on theToolBar
as such:Hope that helps! :)
EDIT:
You can check out the control template for the
ToolBar
here.The
LinearGradientBrush
used looks as such:In the event you just wanted to use this instead of binding. :)
默认模板和样式可以在 MSDN 上找到,您可能可以提取那里的相关位。
The default templates and styles are available on MSDN, you could probably extract the relevant bits from there.
我在应用程序中执行完全相同的操作时发现了一个问题。当我在 XP 机器上和 Vista 机器上运行相同的应用程序时,我发现两个工具栏之间的高度有 2 个像素的差异。
为了解决这个问题,我最终创建了一个 StackPanel,其中包含两个工具栏对象(将背景设置为透明)。
这确保了两个操作系统之间的外观和感觉是相同的(当时公司运行这两个操作系统),并且如果您的一个工具栏在没有另一个工具栏的情况下增加高度,也将为您提供帮助。
I found an issue when doing this exact same thing in an application. When running the same application on an XP machine as I did a Vista machine, I found that there was a 2 pixel difference in the height between the two toolbars.
To get around this, I ended up creating one StackPanel which housed the two tool bar objects (setting the background to be transparent).
This ensured that the look and feel was the same between the two OS's (at the time the company was running both) and will also aid you in the event that one of your toolbars grow in height without the other.