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

ComboBox SelectionChanged command handler is not fired. #240

Open
sam-wheat opened this issue Mar 26, 2023 · 0 comments
Open

ComboBox SelectionChanged command handler is not fired. #240

sam-wheat opened this issue Mar 26, 2023 · 0 comments

Comments

@sam-wheat
Copy link

Repo is here.

I got lucky and guessed a way to make ItemsControl work - my luck has run out with Combobox.

Templated control vs custom control : microsoft/microsoft-ui-xaml#3371

Themes/Generic.xaml:

ItemsControl - works:

<ItemsControl x:Name="peopleItemsControl"
			  ui:FrameworkElementExtensions.AncestorType="local:PeopleControl"
			  ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=People}" >
	<ItemsControl.ItemTemplate>
		<DataTemplate>
			<ToggleSwitch ui:FrameworkElementExtensions.AncestorType="local:PeopleControl" OnContent="{Binding Name}" OffContent="{Binding Name}" >
				<Interactivity:Interaction.Behaviors>
					<Interactions:EventTriggerBehavior EventName="Toggled">
						<Interactions:InvokeCommandAction 
							Command="{Binding (ui:FrameworkElementExtensions.Ancestor).TogglePersonCommand, 
							ElementName=layoutRoot, Mode=TwoWay}" 
							CommandParameter="{Binding}">
						</Interactions:InvokeCommandAction>
					</Interactions:EventTriggerBehavior>
				</Interactivity:Interaction.Behaviors>
			</ToggleSwitch>
		</DataTemplate>
	</ItemsControl.ItemTemplate>
</ItemsControl>

Combobox - does not work:

<ComboBox
	ui:FrameworkElementExtensions.AncestorType="local:PeopleControl"
	Width="150"
	DisplayMemberPath="Name"
	ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=People}" 
	SelectionChangedTrigger="Always" >
	
	<!--Command="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TogglePersonCommand}"-->
	<Interactions:EventTriggerBehavior EventName="SelectionChanged">
		<Interactions:InvokeCommandAction 
			Command="{Binding (ui:FrameworkElementExtensions.Ancestor).TogglePersonCommand, 
			ElementName=layoutRoot, Mode=TwoWay}"
			CommandParameter="{Binding SelectedItem}">
		</Interactions:InvokeCommandAction>
	</Interactions:EventTriggerBehavior>
</ComboBox>

PeopleControl.cs:

	TogglePersonCommand = new AsyncRelayCommand<object>(TogglePersonCommandHandler, (o) =>
    {
        return true; // never fired for combobox
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant