EDIT: I figured it out after 1 hour of trials and errors:
<Button Click="ToggleMenuButton_Click" HorizontalAlignment="Stretch" HorizontalContentAlignment="Left">
<Grid>
<StackPanel Orientation="Horizontal">
<Image x:Name="StrzalkaImage" Source="/MenuSandwich_img_MainAppMenuLeft.png" Width="50" Height="50"/>
<TextBlock x:Name="MenuLabel" Text="Menu" Visibility="Collapsed" Margin="25,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left"/>
</StackPanel>
</Grid>
</Button>
ORIGINAL QUESTION BELOW
I am encountering an issue with the menu items in my WPF application, which is positioned on the left side of the screen.
I've designed the menu to expand or collapse upon clicking the "Menu Sandwich" icon. However, when expanding the menu, the images within it seem to shift inconsistently away from the left side of the screen by varying amounts of pixels. Furthermore, upon collapsing the menu, they fail to return to their designated positions.
I've attempted to troubleshoot the problem by experimenting with properties such as HorizontalAlignment="Left" or "Stretch", as well as trying out a DockPanel instead of a StackPanel and adjusting the architecture, but none of these solutions have resolved the issue.
Below you can find the sample code (all menu items follow the same pattern):
<Grid x:Name="MainAppLeftMenu" Background="green" HorizontalAlignment="Left" Width="50">
<!--<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>-->
<!-- Lewa strona ekranu -->
<StackPanel Height="auto" Orientation="Vertical">
<!-- Przycisk rozszerzający/zamykający menu -->
<Button Click="ToggleMenuButton_Click" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" >
<Image x:Name="StrzalkaImage" Source="/MenuSandwich_img_MainAppMenuLeft.png" Width="50" Height="50"/>
<TextBlock x:Name="MenuLabel" Text="Menu" Visibility="Collapsed" Margin="25,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</StackPanel>
</Grid>
