I am trying to move a tab control on a wpf around dynamically. The tab control is hooked to a timer and basically if you press a button the size is shrunk so it looks and behaves like an expandable panel. However, when I 'shrink' the tab control the width is adjusted centrally, whereas I want the control to stay where it was positioned in the X axis, how do I do that (why they couldn't do control.location(x,y) I don't know!)?
GeneralTransform myTrans = this.tabcontrol1.TransformToAncestor(this);
Point p1 = myTrans.Transform(new Point(0, 0));
I am using the two lines above to开发者_高级运维 get the position, this can be done either via GeneralTransform or visualTreeHelper (which returns a vector) and how do I apply this to the tabcontrol to get it to move?
Thanks, R.
Have you tried using a Canvas as a container to hold the TabControl? Canvas only supports absolute positioning, so you can position it using Canvas.Top
and Canvas.Left
. If you need to stretch the control to fill the area, you can bind to the ActualWidth/ActualHeight of the Canvas container.
Here's an example of what the XAML might look like.
<Canvas x:Name="tabCanvas" Grid.Row="1">
<TabControl x:Name="tabControl" Canvas.Left="0" Canvas.Top="0"
Width="{Binding ElementName=tabCanvas, Path=ActualWidth}"
Height="{Binding ElementName=tabCanvas, Path=ActualHeight}">
<TabItem Header="Item 1" />
<TabItem Header="Item 2" />
</TabControl>
</Canvas>
精彩评论