0

I need to add a MouseBinding to the InputBindings of the ListBoxItems. I know how to this in xaml.

<ControlTemplate TargetType="{x:Type ListBoxItem}">
    <Grid>
        <Border x:Name="MyBorder" ...>
            <Border.InputBindings>
                <MouseBinding MouseAction="LeftClick"
                          Command="{Binding SomeCommand}"/>
            </Border.InputBindings>
        </Border>
    </Grid>
    ...
</ControlTemplate>

But I need to know how to write the above code in code-behind. Is there anyway to do that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user3530012
  • 720
  • 2
  • 20
  • 37

2 Answers2

0

I Think this is what you might look for! Very nice tutorial here: MSDN http://msdn.microsoft.com/en-us/library/system.windows.input.commandbinding.aspx

0

I know it's not the answer, but if someone finds it, refer to https://stackoverflow.com/a/9091989/13179254

As for now, using FrameworkElementFactory is not recommended by Microsoft. Use XAML instead.

An example:

<Image.InputBindings>
    <MouseBinding
        MouseAction="LeftClick"
        Command="{Binding ClearCommand, RelativeSource={RelativeSource TemplatedParent}}"
        CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent}}"/>
</Image.InputBindings>
mihails.kuzmins
  • 1,140
  • 1
  • 11
  • 19