Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualizingStackPanel Spacing property #17336

Open
Neakita opened this issue Oct 23, 2024 · 6 comments · May be fixed by #17356
Open

VirtualizingStackPanel Spacing property #17336

Neakita opened this issue Oct 23, 2024 · 6 comments · May be fixed by #17356
Labels
enhancement feature help-wanted A contribution from the community would be most welcome.

Comments

@Neakita
Copy link

Neakita commented Oct 23, 2024

Is your feature request related to a problem? Please describe.

When using ListBox with ItemPanel = StackPanel it's possible to use StackPanel's Spacing property for, well, adding spacing between items:

<ControlTheme x:Key="{x:Type ListBox}" TargetType="ListBox">
		...
		<Setter Property="ItemsPanel">
			<ItemsPanelTemplate>
				<StackPanel Spacing="12"/>
			</ItemsPanelTemplate>
		</Setter>
                ...

which is simple and straightforward.

But when i need virtualization i have to use VirtualizingStackPanel for ListBox's ItemPanel which doesn't have the Spacing property.

Describe the solution you'd like

Register or AddOwner of StackPanel.SpacingProperty in VirtualizingStackPanel so it's possible to set Spacing between items in VirtualizingStackPanel in the same way as it is with StackPanel:

<ControlTheme x:Key="{x:Type ListBox}" TargetType="ListBox">
		...
		<Setter Property="ItemsPanel">
			<ItemsPanelTemplate>
				<VirtualizingStackPanel Spacing="12"/>
			</ItemsPanelTemplate>
		</Setter>
                ...

which will require changes in Measure/Arrange code.

Describe alternatives you've considered

Simulate Spacing with ListBoxItem margin and compensation of it's margin at the start and end of the ListBox with same but negative margin:

	<ControlTheme x:Key="BaseListBoxItem" TargetType="ListBoxItem">
		...
                <!--Could StackPanel.Spacing be used unless VirtualizingStackPanel is required which doesn't have the Spacing property-->
                <Setter Property="Margin" Value="0 6"/>
		...
	</ControlTheme>
<ControlTheme x:Key="{x:Type ListBox}" TargetType="ListBox">
		...
		<Setter Property="Template">
			...
                        <!--Compensation of ListBoxItem internal margin used to simulate StackPanel.Spacing even if VirtualizingStackPanel is used-->
                        <Decorator Margin="0 -6">
                            ...
                        </Decorator>
	                ...
		</Setter>
		...
</ControlTheme>

which is an ugly crutch and will require additional markup for both Horizontal-Vertical layouts support.

Additional context

No response

@wieslawsoltes
Copy link
Collaborator

You can implement spacing using nth-child selector

@Neakita
Copy link
Author

Neakita commented Oct 24, 2024

You can implement spacing using nth-child selector

Are you suggesting to set default item's margin to something like 0 6 0 0 and set the first item's margin to zero with :nth-child(1) selector?

@maxkatz6
Copy link
Member

Another option, which I often use, is adding Marging to all elements, and adding negative margin on the common container.
But yes, VirtualizingStackPanel.Spacing would be a really nice improvement.

@Neakita
Copy link
Author

Neakita commented Oct 24, 2024

Another option, which I often use, is adding Marging to all elements, and adding negative margin on the common container.

Exactly what i did for now, see Describe alternatives you've considered section.

@timunie
Copy link
Contributor

timunie commented Oct 24, 2024

@Neakita maybe you want to file a PR?

@timunie timunie added the help-wanted A contribution from the community would be most welcome. label Oct 24, 2024
@Neakita
Copy link
Author

Neakita commented Oct 24, 2024

@Neakita maybe you want to file a PR?

I do not exclude this possibility. I'll probably try to do this over the next few days if I don't have any difficulties cloning the repository, testing changes, or anything else.

@Neakita Neakita linked a pull request Oct 26, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature help-wanted A contribution from the community would be most welcome.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants