0

I have two ToolBars 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?

Ian Ringrose
  • 51,220
  • 55
  • 213
  • 317
Fjodr
  • 919
  • 13
  • 32

3 Answers3

2

Here's one way you could do it. Say one of your toolbars' name is "toolBar." Bind the Background property on the StackPanel to the Background property on the ToolBar as such:

<StackPanel Background="{Binding Path=Background, ElementName=toolBar}" />

Hope that helps! :)

EDIT:

You can check out the control template for the ToolBar here.

The LinearGradientBrush used looks as such:

<LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
  <GradientBrush.GradientStops>
    <GradientStopCollection>
      <GradientStop Color="#FFF" Offset="0.0"/>
      <GradientStop Color="#AAA" Offset="1.0"/>
    </GradientStopCollection>
  </GradientBrush.GradientStops>
</LinearGradientBrush>

In the event you just wanted to use this instead of binding. :)

Ashley Grenon
  • 9,305
  • 4
  • 41
  • 54
  • Now I feel ashamed, Binding was the most simple way and the more efficient. It will work whenever the style of the toolbar change. Thanks a lot for this one! – Fjodr Apr 06 '11 at 16:45
0

The default templates and styles are available on MSDN, you could probably extract the relevant bits from there.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • Still not what I was looking for, as I have visited this site before, but at least I believe that I got the endPoint and StartPoint right here. Thanks for the help. – Fjodr Apr 06 '11 at 16:15
0

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.

fatty
  • 2,453
  • 2
  • 25
  • 24