Spawn Menu at Position
Hello, I've been getting along with my GUI project for a while but I have come across a minor annoyance when dealing with relative and absolute positions of elements
in this case, I have a button that needs to spawn a menu "below" it. I am looking at spawning a Grid at that buttons position with the height of the button as an offset.
unfortunately, when trying to find the screen position I keep getting insane numbers such as -666 and 2280 for my margins and Noesis crashes because it doesn't like these numbers
I think its a failure on my part when dealing with relative vs spacial and screen resolution vs real resolution
below is some code where I have decided to stop and ask for help
Ideally, I'd like for it to be a grid if that's any consequence
in this case, I have a button that needs to spawn a menu "below" it. I am looking at spawning a Grid at that buttons position with the height of the button as an offset.
unfortunately, when trying to find the screen position I keep getting insane numbers such as -666 and 2280 for my margins and Noesis crashes because it doesn't like these numbers
I think its a failure on my part when dealing with relative vs spacial and screen resolution vs real resolution
below is some code where I have decided to stop and ask for help
Ideally, I'd like for it to be a grid if that's any consequence
Code: Select all
public void Menu(object sender, RoutedEventArgs e)
{
Point _Position = ((Noesis.Button)sender).PointFromScreen(new Point(0f, 0f));
Vector2 _size = new Vector2(
((Noesis.Button)sender).Width,
((Noesis.Button)sender).Height
);
Noesis.Grid _panel = new Noesis.Grid
{
Margin = Thickness.Parse("" + _Position.X + _size.x + "," + _Position.Y + _size.y + "0,0"),
MinWidth = 150,
MaxWidth = 250,
MinHeight = 12
};
ColumnDefinition Options = new ColumnDefinition { Width = Noesis.GridLength.Auto, MaxWidth = 250 };
ColumnDefinition Scroll = new ColumnDefinition { Width = Noesis.GridLength.Parse("12") };
_panel.ColumnDefinitions.Add(Options);
_panel.ColumnDefinitions.Add(Scroll);
Re: Spawn Menu at Position
I have been playing with it further
works, However, I can't seem to add the button's height to it, I get an error Not a Number "NaN" otherwise it's fine.
casting is apparently redundent.
Not sure if a bug, or misinterpretation
Code: Select all
public void StaticMenu(object sender, RoutedEventArgs e)
{
Button origin = ((Noesis.Button)sender);
Point position = origin.PointToScreen(new Point(10f , 0f));
Menu.Margin = Thickness.Parse(position.X.ToString() + "," + position.Y.ToString() + ",0,0");
casting is apparently redundent.
Code: Select all
Point position = origin.PointToScreen(new Point(0f, origin.Height + 0f));
-
-
sfernandez
Site Admin
- Posts: 2064
- Joined:
Re: Spawn Menu at Position
Hi, as you found you need to use PointToScreen to calculate position in screen coordinates.
And Width/Height properties are the source for element size calculation, but the final size is stored in ActualWidth/ActualHeight, so your code should look like this:
And I suggest using a TranslateTransform as RenderTransform to position your menu instead of modifying Margin property:
And Width/Height properties are the source for element size calculation, but the final size is stored in ActualWidth/ActualHeight, so your code should look like this:
Code: Select all
Point position = origin.PointToScreen(new Point(0f, origin.ActualHeight));
Code: Select all
Menu.RenderTransform = new TranslateTransform { X = position.X, Y = position.Y };
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest