You can connect the UIElement.IsVisibleChanged event in userControl:
<ctrls:Login IsVisibleChanged="Control_VisibleChanged"/>
Code behind:
private void Control_VisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if ((bool)e.NewValue) {
If you want to run Timer , I do not see a problem with this code.
But, if you still want this notification to be sent to the ViewModel, you can create an ICommand in the UserMontrol ViewModel and bind this event using interaction triggers :
<ctrls:Login> <i:Interaction.Triggers> <i:EventTrigger EventName="IsVisibleChanged"> <i:InvokeCommandAction Command="{Binding VisibleChangedCommand}"/> </i:EventTrigger> </i:Interaction.Triggers> </ctrls:Login>
You can link to this article here if interaction triggers are something new for you.
source share