Using interaction trigger to call visibility changed method WPF

前端 未结 1 983
孤独总比滥情好
孤独总比滥情好 2021-01-13 11:45

What I would like to figure out is two things, how to get a trigger occurring when a user control\'s visibility is changed and passing the value of visibility through as a p

1条回答
  •  萌比男神i
    2021-01-13 12:15

    First, we need to set TargetObject property to viewmodel/DataContext, because method to be invoked is available in the viewmodel :

    ......
    
        
            
        
    
    ......
    

    Second, EventTrigger doesn't seems to work specifically with IsVisibleChanged event. So code snippet above works for other event, but not IsVisibleChanged. We can find a workaround in the answer to this SO question, by using PropertyChangedTrigger to listen to Visibility property changed, instead of listening to IsVisibleChanged event :

    
        
            
        
    
    

    Third, CallMethodAction doesn't seems to provide a way to pass parameter to the method. To be able to invoke a method with parameter we better use InvokeCommandAction instead of CallMethodAction as suggested here and also suggested by @Rohit in your previous question.

    0 讨论(0)
提交回复
热议问题