I now realize that if I don't answer to my own question no one will be able to mark my work-around as an answer. So here's the full code. I implemented it as a PRISM behavior.
public static class PopupRightAlignBehavior
{
public static readonly DependencyProperty InstanceProperty =
DependencyProperty.RegisterAttached("Instance", typeof(object), typeof(PopupRightAlignBehavior), new PropertyMetadata(OnSetInstanceCallback));
public static object GetInstance(DependencyObject obj)
{
return (object)obj.GetValue(InstanceProperty);
}
public static void SetInstance(DependencyObject obj, object value)
{
obj.SetValue(InstanceProperty, value);
}
private static void OnSetInstanceCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var popup = (Popup)d;
popup.Opened -= OnPopupOpened;
popup.Opened += OnPopupOpened;
}
private static void OnPopupOpened(object sender, System.EventArgs e)
{
var popup = (Popup)sender;
popup.Dispatcher.BeginInvoke(() => popup.HorizontalOffset = -popup.ActualWidth);
}
}
R4cOON
2010-03-02 10:25:54