I have also been trying to do something like this as well and preferred doing things in XAML. I had problems with using Placement=Left on multi-monitors because the popup will jump to another screen and it'll be way off in the middle. It was more reliable doing Position=Relative and adjusting the offset using a binding to the container it will aling with.
<Popup x:Name="RightPopupContainer"
StaysOpen="False"
Placement="Relative"
PlacementTarget="{Binding ElementName=BigContainer}"
Height="{Binding ElementName=BigContainer, Path=ActualHeight}"
AllowsTransparency="True"
PopupAnimation="Fade">
<Popup.HorizontalOffset>
<MultiBinding Converter="{StaticResource SubtractionConverter}">
<MultiBinding.Bindings>
<Binding ElementName="BigContainer" Path="ActualWidth" />
<Binding ElementName="RightPopupContainer" Path="Child.ActualWidth" />
</MultiBinding.Bindings>
</MultiBinding>
</Popup.HorizontalOffset>
</Popup>
The SubtractionConverter is a simple multibinding converter that subtracts the BigContainer.ActualWidth from the RightPopupContainer.Child.ActualWidth (popup always has width = 0, the child has the size). This allows it to be placed exactly to the edge of the container and it automatically updates when either container size changes.
Instead of multi-bindings, here is another option that performs the same results.
In the UserControl or Window that contains your Popup, create an event listener for LayoutUpdated in the code-behind. In the code behind you can do logic such as:
private void UpdateElementLayouts(object sender, System.EventArgs e)
{
if (RightPopupContainer?.IsOpen == true && RightPopupContainer.Child is UserControl content)
{
RightPopupContainer.HorizontalOffset = BigContainer.ActualWidth - content.ActualWidth;
}
}