views:

40

answers:

1

I have a ToolBar WPF control which has a Stackpanel docked to right. I use this toolbar control in 3 other WPF controls by adding in the XAML. When I verify in the XAML the Stackpanel location is same for all 3 controls. But when I run my application, for one of the 3 controls, the StackPanel in the ToolBar control shifts to left.

   <StackPanel DockPanel.Dock="Right" Orientation="Horizontal" HorizontalAlignment="Right" Name="stackButtons" >

Any idea? Appreciate your help..

+1  A: 

I'll try three guesses.

1) You have some explicit code which changes the DockPanel.Dock property. (Highly unlikely, I'll admit)

2) The stack panel isn't actually shifting to the left. The enclosing DockPanel is actually shifting to the left, and it's still the right most control in a left most dock panel.

3) The window holding the dock panel has some additional default styles (styles which have a TargetType but not keys), and these styles are screwing things up somehow. This is unlikely, as you are setting the HorizontalAlignment as an explicit property, and explicit properties override style properties. But styles can continually surprise.

Anyway, these stabs-in-the-dark might give you ideas as to where to look.

Andrew Shepherd
I think 2) is the most likely reason. @Vinjamuri: To check out 2), you can set the Background property for all relevant panels to a different value, like one set to `Green`, the next to `Red`, another one to `Blue`. Then debug, and you will see how much space they take.
gehho