Page 1 of 1

How to determine what UIElement::Layout changed?

Posted: 13 Jun 2019, 20:25
by realesmedia
analog WPF event
 UIElement.LayoutUpdated()

Re: How to determine what UIElement::Layout changed?

Posted: 17 Jun 2019, 17:01
by sfernandez
WPF's LayoutUpdated event occurs when the layout of the various visual elements associated with the current Dispatcher changes. That means that elements that have been measured and arranged can be different from the one raising the event. At the end the event will only specify if any element was measured/arranged, nothing else.

Is that something you are interested in?

Re: How to determine what UIElement::Layout changed?

Posted: 18 Jun 2019, 10:19
by realesmedia
I needed to subscribe to the event of changing the position (dragging) + zoom of the element relative to parent

I only needed an event

I have already found another solution)))

thanks

Re: How to determine what UIElement::Layout changed?

Posted: 06 Jul 2022, 18:56
by Thraka
I hate it when someone just says "I found a solution" but doesn't post it. Others may have the same issue as you!

Please share what you did. I'm looking for a layout event also. I want to align some data with the screen position and size of the element after it changes. I have no idea how to do this! :(

Re: How to determine what UIElement::Layout changed?

Posted: 07 Jul 2022, 17:30
by Thraka
The other thing I find a little odd, besides the missing event, is that a user control doesn't have anything to override related to this either. My other thought was creating a user control that could respond to the layout changes and inform my game. But there aren't very many methods to override.

Re: How to determine what UIElement::Layout changed?

Posted: 09 Jul 2022, 13:54
by Logrus
I hate it when someone just says "I found a solution" but doesn't post it. Others may have the same issue as you!

Please share what you did. I'm looking for a layout event also. I want to align some data with the screen position and size of the element after it changes. I have no idea how to do this! :(
I had to subscribe to notifications of Movement and resizing of parent elements. The solution depends on the xaml hierarchy.
	
	ConnectorControl::ConnectorControl()
	{
		InitializeComponent();

		Loaded() += [this] (BaseComponent*, const RoutedEventArgs& e) {
	
			if (m_node = Helper::GetParentRecursive<NodeControl>(this)) {
				if (auto behaviors = NoesisApp::Interaction::GetBehaviors(m_node)) {
					if (auto behavior = Noesis::DynamicCast<TransformBehavior*>(behaviors->Get(0))) {
						behavior->TranslateChanged() += Noesis::MakeDelegate(this, &ConnectorControl::OnLayoutUpdated);
					}
				}
			}

			if(m_control = Helper::GetParentRecursive<ItemsControl>(this)) {
				if (auto parent = m_control->GetParent()) {
					parent->SizeChanged() += MakeDelegate(this, &ConnectorControl::OnLayoutUpdated);
				}
			}

			if (auto graph = Helper::GetParentRecursive<NodeGraphControl>(this)) {
 				m_canvas = graph->FindName<Canvas>("PART_Canvas");
 				OnLayoutUpdated();
			}
		};
	}

Re: How to determine what UIElement::Layout changed?

Posted: 09 Jul 2022, 20:17
by Thraka
Thanks. I'll look into using that! It would be nice if this was supported by the API :) I see there is a bug that's been opened for years related to adding it.

Re: How to determine what UIElement::Layout changed?

Posted: 11 Jul 2022, 18:51
by sfernandez
All elements have a SizeChanged event that indicates its render size changed, is that what you are looking for?

Re: How to determine what UIElement::Layout changed?

Posted: 13 Jul 2022, 15:21
by Logrus
I have a ConnectionControl that connects nodes via Pin.
The connection should monitor any events that lead to changes in Pin positions.

in my opinion, the notification UIElement.LayoutUpdated() is best suited for this.

Re: How to determine what UIElement::Layout changed?

Posted: 15 Jul 2022, 12:07
by sfernandez
I agree, for that scenario having the LayoutUpdated event would help, although as I mentioned earlier, that event is a bit confusing because it is raised when ANY element in the tree gets updated, not only when the element where you register the event handler changes its layout.

We will implement the LayoutUpdated event for the next release: #1041