开发者

Attach Prism Command to Grid?

Is it possible to create a command behavior using Prism's CommandBehaviorBase class for Silverlight's grid? I know that it is only 开发者_StackOverflow中文版intended for actual controls, so I was wondering if anyone might know if a workaround. I would like to create an attachable mouse over behavior for a grid, that executes a specific command, and ideally would like to use Prism for this approach, just can't seem to use CommandBehaviorBase for a Grid.

Thanks.


The arguably easier way to achieve this is to use Triggers. Doesn't require you to write any code, all you have to do is this:

<Grid>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseEnter">
            <si:InvokeDataCommand Command="{Binding DoSomethingCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    ...
</Grid>

Here the DoSomethingCommand (defined in a ViewModel) will trigger when MouseEnter event is fired on the Grid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜