I saw an article detailing how to do this using attached behaviors which I like a lot. However, the download doesn't work and the article is pretty old (a couple of years).

What is the current way for handling events like this without using codebehind? Are there any that are MVVM-specific?

有帮助吗?

解决方案

You can use the expression blend extensions:

<ListBox>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">
            <i:InvokeCommandAction Command="CommandNameHere"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
</ListBox>

It is another dependency, but it does seem to work well in .NET 4.

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=10801

Edit: You can also use the CommandParameter To Pass In Extra Things (Like The Selected Item View Model)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top