Setting auto-generated listboxitem properties

I am trying to set inputbindings of automatically generated ListBoxItems of a DataBox data list. The code below does not work. The compiler complains that “InputBindings” cannot be set because it does not have access to access. ”What is the correct syntax for setting InputBindings?

    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="ListBoxItem.InputBindings">
                <Setter.Value>
                    <MouseBinding Command="{Binding OpenCommand}" Gesture="LeftDoubleClick"/>
                </Setter.Value>
            </Setter>
        </Style>
    </ListBox.ItemContainerStyle>

PS: Wiring does not work with Opera 10.51

+3
source share
2 answers

This is really hard.

I found two suggested solutions for you, and I'm not very easy to implement, I'm afraid. Hope this works for you!

+3
source

"" , Loaded ListBoxItem, .

        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">
                <EventSetter Event="Loaded" Handler="ListBoxItem_Loaded" />
            </Style>
        </ListBox.ItemContainerStyle>

InputBindings .

Private Sub ListBoxItem_Loaded(ByVal sender As System.Object, ByVal e As RoutedEventArgs)
    Dim item = DirectCast(sender, ListBoxItem)
    item.InputBindings.Add(New KeyBinding(UserCommands.EditCommand, Key.Enter, ModifierKeys.None))
    item.InputBindings.Add(New KeyBinding(UserCommands.DeleteCommand, Key.Delete, ModifierKeys.None))
    item.InputBindings.Add(New MouseBinding(UserCommands.EditCommand, New MouseGesture(MouseAction.LeftDoubleClick)))
End Sub

, MVVM, , .

+1

Source: https://habr.com/ru/post/1739711/


All Articles