Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

WPF Popup Position: Down, Left to Right
 
How to place the popup below a UIElement, but from left to right.
 
Problem:
If you arrange a WPF popup with the setting Placement = Bottom below a UIElement,
Then the popup itself is placed below the range, but the size extends from right to left.
In Placement = Left, the popup is opened from left to right, but it appears to the top right of the UIElements.
 
Solution:
The popup should appear below the UI element, but be expanded from left to right.

 
Solution by C # Code
You must assign the horizontal and vertical offset to the pop-up before opening.
Please note that the horizontal offset must be from right to left, ie negative.

//< open Popup >
popupFolders.VerticalOffset = BaseControl.ActualHeight;
popupFolders.HorizontalOffset = - BaseControl.ActualWidth;
popupFolders.IsOpen = true;
//</ open Popup >

 
 
XAML Code of the range. Here within a UserControl

<UserControl
.. >
 
<Grid Name="BaseControl" >

<StackPanel x:Name="pnlPath" Orientation="Horizontal" >
<Image x:Name="imgFolder" Source="/wpf_Browse_Folders;component/_images/imgExpand_Right.png" VerticalAlignment="Top" />
<Label x:Name="lblPath" Content="Path" VerticalAlignment="Top" />
</StackPanel>
<Rectangle Name="posFolders" >

</Rectangle>

<Popup Name="popupFolders" IsOpen="False" MouseLeave="Popup_MouseLeave"
PlacementTarget="{Binding ElementName=pnlPath}"
Placement="Left"
>
<ListBox Name="lstFolders">
</ListBox>
</Popup>

</Grid>

</UserControl>

 
 
Position Bottom:
Popup Placement = Bottom but with stretch to the left

 
XAML on this example:

<Popup Name="popupFolders" IsOpen="False" MouseLeave="Popup_MouseLeave"
Placement="Bottom" PlacementTarget ="{Binding ElementName=BaseControl}" >
<ListBox Name="lstFolders">
</ListBox>
</Popup>

 
 
Adding the HorizontalAlignment to the popup is unsuccessful

HorizontalAlignment="Left"

 
Position Left
Without the script adaptation, the position = Left parameter positions to the upper right of a UIElement
Mobile
»
WPF Datagrid: Set Color of Row when it has no Focus
»
WPF Datagrid: Change the Color of Selected Row
»
WPF: Change Selected Row Color in DataGrid
»
WPF: Read SelectedItem from DataGrid with Dynamic As Anonymous Type
»
WPF: Elements too wide, edge Cut off
»
Solved: System.InvalidCastException HResult 0x80004002 in Select DataGrid
»
WPF: Combobox Selected Value
»
WPF Datagrid: Column is not displayed
»
WPF: Show video in preview
»
WPF Webbrowser: Suppress Java Errors or Set WebBrowser to Silent

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de