Firing a Command within EventTrigger of a style?

后端 未结 2 1425
夕颜
夕颜 2021-02-08 08:01

As you know you can\'t bind an Event directly to a command without a behaviour:


    
        

        
相关标签:
2条回答
  • Since you are retemplating the DataGridCell, you could add the triggers to the root element in the control template. Something like:

    <ControlTemplate TargetType="{x:Type DataGridCell}">
        <Grid x:Name="root" Background="Transparent">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="PreviewMouseDoubleClick">
                    <i:InvokeCommandAction Command="{Binding TradeEntryCommand}" />
                </i:EventTrigger>                            
            </i:Interaction.Triggers>
        </Grid>
    </ControlTemplate>
    
    0 讨论(0)
  • 2021-02-08 08:48

    Thats a version I am using for a Button-command in a similar situation (Button in DataGridRow, Command on DataGrid should be invoked by the Button and I need the DataContext of the row in my command). You would have to use the command of the InvokeCommandAction of the doubleClick-trigger instead, but then it should work as well, I suppose.

    Good luck!

        <DataTemplate>
                <TextBlock>                             
               <Button x:Name="cmdButton"                            
                                        Command="{Binding Path=DataContext.CommandNameInViewModel, 
                                            RelativeSource={RelativeSource AncestorType={x:Type TypeOfAncestorWithTheViewModel}}}"
                                        CommandParameter="{Binding}" >      
                                        Do something
            </Button>
    
        </TextBlock>  
    </DataTemplate>     
    
    0 讨论(0)
提交回复
热议问题