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

TreeView - Selection state inconsistency between ContextMenu and ContextFlyout implementations #17669

Open
Coloris opened this issue Dec 2, 2024 · 0 comments
Labels

Comments

@Coloris
Copy link

Coloris commented Dec 2, 2024

Describe the bug

When using a TreeView with ContextFlyout as a context menu, the selection state / focus of TreeView items is lost after interacting with the MenuFlyout, Subsequent item selection requires two clicks instead of the expected single click behavior.

However, when using the traditional ContextMenu, the selection state is properly maintained.

To Reproduce

Working example with ContextMenu

<TreeView ItemsSource="{Binding Items}">
	<TreeView.ItemTemplate>
		<TreeDataTemplate ItemsSource="{Binding Children}">
			<TextBlock Text="{Binding Header}" Background="Transparent">
				<TextBlock.ContextMenu>
					<ContextMenu>
						<MenuItem Header="{Binding Header}"/>
					</ContextMenu>
				</TextBlock.ContextMenu>
			</TextBlock>
		</TreeDataTemplate>
	</TreeView.ItemTemplate>
</TreeView>

ContextMenu

Issue example with MenuFlyout

<TreeView ItemsSource="{Binding Items}">
	<TreeView.ItemTemplate>
		<TreeDataTemplate ItemsSource="{Binding Children}">
			<TextBlock Text="{Binding Header}" Background="Transparent">
				<TextBlock.ContextFlyout>
					<MenuFlyout ShowMode="TransientWithDismissOnPointerMoveAway">
						<MenuItem Header="{Binding Header}"/>
					</MenuFlyout>
				</TextBlock.ContextFlyout>
			</TextBlock>
		</TreeDataTemplate>
	</TreeView.ItemTemplate>
</TreeView>

ContextFlyout

Expected behavior

ContextFlyout should maintain consistent selection behavior like the existing ContextMenu implementation when used in a TreeView control

Avalonia version

11.2.2

OS

Windows 11 [Version 10.0.26100.2454]

Additional context

No response

@Coloris Coloris added the bug label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant