Share via

HorizontalStackLayout Crashes on Negative Spacing

Kenneth R. Jones 46 Reputation points
2023-12-19T15:16:26.8533333+00:00

The Visual Studio debugger keeps crashing when I attempt to enter a negative value for spacing in a HorizontalStackLayout. According to Microsoft's website, I am allowed to use a negative value here.

I am creating a card layout and I would like the cards (images) to overlap for the card game. Why does this crash the debugger?

Reference stating this is allowed.

Thanks.

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"              
	x:Class="GinRummyMAUI.MainPage">
<StackLayout>          
	<HorizontalStackLayout
		x:Name="humanCardLayout"             
		HorizontalOptions="CenterAndExpand"             
		Spacing="-5">              
	
	<Image                 
		x:Name="Card1"                  
		Source="back_purple.png"/>              

	<Image                 
		x:Name="Card2"                  
		Source="back_purple.png"/>           

	</HorizontalStackLayout>      
</StackLayout>  
</ContentPage>
Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
2023-12-20T02:54:59.76+00:00

Hello,

Thank you for your feedback. By testing your code, this problem will occur on the Windows platform.

For this issue, it is recommended that you post it on GitHub to make our development team aware of this.

In addition, for use cases where you need overlapping controls, such as overlapping cards, it is recommended that you use AbsoluteLayout to achieve this requirement.

<StackLayout>
        <AbsoluteLayout>
            <Image Source="dotnet_bot.png" AbsoluteLayout.LayoutBounds="0,0,100,100"/>
            <Image Source="dotnet_bot.png" AbsoluteLayout.LayoutBounds="40,0,100,100"/>
            <Image Source="dotnet_bot.png" AbsoluteLayout.LayoutBounds="80,0,100,100"/>
            <Image Source="dotnet_bot.png" AbsoluteLayout.LayoutBounds="120,0,100,100"/>
        </AbsoluteLayout>
</StackLayout>

Best Regards,

Alec Liu.


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.