The control Popupis left-aligned by default. Its left edge aligns with the left edge of its parent.
I would like to make the control aligned to the right, so that its right edge is aligned with the right edge of its container.
I want this to be dynamic because I am dynamically linking the data and I don't know how big the popup will be.
I tried playing with events Opened, SizeChangedand Loadedto get the width Childand set it to HorizontalOffset, but there seemed to be problems with synchronization. Basically, it works great the first time the control is loaded, and then never after (the value HorizontalOffsetis 0).
This is mistake? Am I doing it wrong?
EDIT I worked. There seem to be issues of the time. If I hook up the event Openedand install asynchronously HorizontalOffsetusing Dispatcher, then it works: (
private static void OnPopupOpened(object sender, System.EventArgs e)
{
var popup = (Popup)sender;
popup.Dispatcher.BeginInvoke(() => popup.HorizontalOffset = -popup.ActualWidth);
}
code>
EDIT 2 Now I understand that I was doing something stupid. I wanted Popupout ComboBoxwas right-aligned. I did not see that it was reinitialized in a call to a private method ArrangePopup.
I tried to inherit from ComboBoxto override the allocation function, but I have to do something wrong because it still does not work, although I tried methods that callArrangePopup
Greetings.
source
share