Set Interaction.Triggers to ListBoxItem

后端 未结 3 1321
感情败类
感情败类 2021-01-25 05:42

I have set Interaction.Triggers to ListBox and perform respective TargetedTriggerAction when \'SelectionChanged\' event occurs, like below.



        
相关标签:
3条回答
  • 2021-01-25 06:08
      <ListBox.Triggers>
                        <EventTrigger RoutedEvent="PreviewMouseDown">
                            <action:WorksheetListBoxAction />
                        </EventTrigger>
                    </ListBox.Triggers>
    

    You can do the same without use of Interactivity.dll for event handling.

    0 讨论(0)
  • 2021-01-25 06:30

    You can try something like this:

        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="PreviewMouseDown">
                    <EventTrigger.Actions>
                        <action:WorksheetListBoxAction />
                    </EventTrigger.Actions>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    
    0 讨论(0)
  • 2021-01-25 06:32

    you can do it the PreviewMouseDown event on the ListBoxItem

    <ListBox ItemsSource="{StaticResource Data}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Button Name="TaskButton" Content="{Binding}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ListBoxItem}">
                        <EventSetter Event="PreviewMouseDown"
                                     Handler="ItemOnPreviewMouseDown" />
                    </Style>
                </ListBox.ItemContainerStyle>
            </ListBox>
    
            private void ItemOnPreviewMouseDown(
                object sender, MouseButtonEventArgs e)
            {
    
                ((ListBoxItem) sender).IsSelected = true;
    
            }
    
    0 讨论(0)
提交回复
热议问题