1

I have CustomControl which can appear in multiple way. I have designed a Template for each situation like (dragging, placing, ...)

When a user fires MouseLeftButtonDown on the Control, The Event handler will changes the Template of this control and I will make it Draggable. in this Process ActualWidth and ActualHeight of the Control will have a huge change.

EDIT: Here is it ScreenShot: enter image description here

I must wait for Applying the new Template and then calculate the ActualSize.

How can I wait for this Template Changes in Runtime ?

RezaNoei2
  • 31
  • 5

1 Answers1

0

Don't use a template for everything. It is best to use c# code rather than xaml to control such requirements as yours, because it involves a lot of complex ui operations.

nabian
  • 116
  • 3
  • I have read this answer https://stackoverflow.com/questions/5755455/how-to-set-control-template-in-code and here it says that defining a controltemplate in CodeBehind is Deprecated and we It says we not all functionality are available through this way. – RezaNoei2 Sep 20 '18 at 10:59
  • I agree with him, exactly. I mean drag or related mouse events do not rely on templates to implement.The controls involved can be defined in the template, then get them through the gettemplatechild method,in the end, you're free to control them. – nabian Sep 20 '18 at 11:17
  • I have added an screenshot to the post. My Controls are UserControl Actually and I should summrize them in drag so i can see the right place to putting them. so I need to change their Template on each event. – RezaNoei2 Sep 20 '18 at 15:12
  • After changing their template; their Width and Height will changes. I cant see the changes after setting the new Template to them so I must wait for the changes that is made in Template. – RezaNoei2 Sep 20 '18 at 15:15