Ich schlage vor, Sie das einmal mit Behavior.I'm Zugabe Beispiel mit MenuItem aber das gleiche für jede Kontrolle mit PopUp (wie ComboBox)
Auf Ihrem XAML das Verhalten auf den Menüpunkt anhängen hinzufügen:
<Menu>
<MenuItem ItemsSource="{Binding GlanceOptions, Mode=OneWay}">
<interactivity:Interaction.Behaviors>
<behaviors:MenueItemSubMenuPlacementBehavior />
</interactivity:Interaction.Behaviors>
<MenuItem.Header>
<Border
Cursor="Arrow"
BorderThickness="1,1,1,0" >
<Path x:Name="DropDownIcon"
VerticalAlignment="Center"
Data="M0,0L2,3 4,0z"
/>
</Border>
</MenuItem.Header>
</MenuItem >
</Menu>
Das Verhalten Code:
public class MenueItemSubMenuPlacementBehavior : Behavior<MenuItem>
{
private PlacementMode _previousPlacementMode;
private CustomPopupPlacementCallback _previousCallback;
private Popup _menuItemPopUp;
protected override void OnAttached()
{
base.OnAttached();
Initialize();
}
private void Initialize()
{
if (AssociatedObject == null)
return;
if (_menuItemPopUp == null)
{
_menuItemPopUp = AssociatedObject?.Template?.FindName("PART_Popup", AssociatedObject) as Popup;
if (_menuItemPopUp == null)
{
AssociatedObject.Loaded -= AssociatedObject_Loaded;
AssociatedObject.Loaded += AssociatedObject_Loaded;
return;
}
_previousPlacementMode = _menuItemPopUp.Placement;
_previousCallback = _menuItemPopUp.CustomPopupPlacementCallback;
_menuItemPopUp.Placement = PlacementMode.Custom;
_menuItemPopUp.CustomPopupPlacementCallback = CustomPopupPlacementCallback;
}
}
private void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
{
AssociatedObject.Loaded -= AssociatedObject_Loaded;
if (_menuItemPopUp != null)
return;
_menuItemPopUp = VisualTreeHelpers.FindFirstChild<Popup>(AssociatedObject) as Popup;
if (_menuItemPopUp == null)
return;
_previousPlacementMode = _menuItemPopUp.Placement;
_previousCallback = _menuItemPopUp.CustomPopupPlacementCallback;
_menuItemPopUp.Placement = PlacementMode.Custom;
_menuItemPopUp.CustomPopupPlacementCallback = CustomPopupPlacementCallback;
}
protected override void OnDetaching()
{
base.OnDetaching();
if(AssociatedObject != null)
{
AssociatedObject.Loaded -= AssociatedObject_Loaded;
}
if (_menuItemPopUp != null)
{
_menuItemPopUp.Placement = _previousPlacementMode;
_menuItemPopUp.CustomPopupPlacementCallback = _previousCallback;
_previousCallback = null;
}
}
private CustomPopupPlacement[] CustomPopupPlacementCallback(Size popupSize, Size targetSize, Point offset)
{
var rightPlacedPopupX = offset.X;
var rightPlacedPopupY = offset.Y + (AssociatedObject.ActualHeight * YourLogic);
return new[]
{
new CustomPopupPlacement(new Point(rightPlacedPopupX, rightPlacedPopupY), PopupPrimaryAxis.Horizontal),
};
}
}
Dieser Thread helfen könnten: http://stackoverflow.com/questions/5340640/wpf-combobox-popup-placement-bottom-and-aligned-to-the-right -edge – geostocker
Ich bin bei der Suche auf diesen Thread gestoßen, aber er erreicht nicht das, wonach ich suche. – TheOne
Irgendwelche Ideen Jungs? – TheOne