- jc_lvngstn
- Posts: 34
- Joined:
Dragging panels?
How would you go about moving an entire panel, such as a dock panel that is the root element?
I noticed several examples where there is a canvas element, and you can use SetTop and other methods. But I don't see anything for a DockPanel. I tried using SetTransform, but that didn't appear to change screen position.
Ultimately, I'm trying to drag the panel around. I'm trying to do this via code behind, in C#. I can detect mouse/down and in my Update statement I'd like to translate the panel based on mouse position.
Thanks!
I noticed several examples where there is a canvas element, and you can use SetTop and other methods. But I don't see anything for a DockPanel. I tried using SetTransform, but that didn't appear to change screen position.
Ultimately, I'm trying to drag the panel around. I'm trying to do this via code behind, in C#. I can detect mouse/down and in my Update statement I'd like to translate the panel based on mouse position.
Thanks!
-
sfernandez
Site Admin
- Posts: 3093
- Joined:
Re: Dragging panels?
Hi,
To move an element respect to the parent container you should use the RenderTransform property. For example:
Then you can get a reference to that panel during start up as usual:
And get the render transform to update it later on mouse events:
To update transform you just set the X and Y properties of the TranslateTransform:
And that's all
To move an element respect to the parent container you should use the RenderTransform property. For example:
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel x:Name="MovingPanel">
<DockPanel.RenderTransform>
<TranslateTransform X="0" Y="0"/>
</DockPanel.RenderTransform>
<!-- Panel contents -->
</DockPanel>
</Grid>
Code: Select all
NoesisGUIPanel gui = GetComponent<NoesisGUIPanel>();
FrameworkElement root = gui.GetRoot<FrameworkElement>();
this._movingPanel = root.FindName<DockPanel>("MovingPanel");
Code: Select all
this._movingPanelTransform =
this._movingPanel.GetRenderTransform().As<TranslateTransform>();
Code: Select all
this._movingPanelTransform.SetX(newPosition.x);
this._movingPanelTransform.SetY(newPosition.y);
- jc_lvngstn
- Posts: 34
- Joined:
Re: Dragging panels?
That worked beautifully!
One thing that threw me off was...you HAVE to define the RenderTransform and TranslateTransform in your XAML, otherwise it shows the TranslateTransform as null in your script. I guess I forgot this about XAML. I would have expected it to exist regardless.
One thing that threw me off was...you HAVE to define the RenderTransform and TranslateTransform in your XAML, otherwise it shows the TranslateTransform as null in your script. I guess I forgot this about XAML. I would have expected it to exist regardless.
-
sfernandez
Site Admin
- Posts: 3093
- Joined:
Re: Dragging panels?
The default value for UIElement.RenderTransform property is the Identity transform. User can override that value with any transform he needs: TranslateTransform, ScaleTransform, RotateTransform, SkewTransform, or TransformGroup (that could contain a list of transforms).
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 6 guests