Compartir a través de


UIScreen.Notifications.ObserveModeDidChange Método

Definición

Sobrecargas

ObserveModeDidChange(EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la ModeDidChangeNotification constante.

ObserveModeDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la ModeDidChangeNotification constante.

ObserveModeDidChange(EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la ModeDidChangeNotification constante.

public static Foundation.NSObject ObserveModeDidChange (EventHandler<Foundation.NSNotificationEventArgs> handler);
static member ObserveModeDidChange : EventHandler<Foundation.NSNotificationEventArgs> -> Foundation.NSObject

Parámetros

handler
EventHandler<NSNotificationEventArgs>

Método que se invoca cuando se publica la notificación.

Devoluciones

Objeto token que se puede usar para dejar de recibir notificaciones mediante su eliminación o su paso a RemoveObservers(IEnumerable<NSObject>)

Comentarios

En el ejemplo siguiente se muestra cómo puede usar este método en el código.

//
// Lambda style
//

// listening
notification = UIScreen.Notifications.ObserveModeDidChange ((sender, args) => {
    /* Access strongly typed args */
    Console.WriteLine ("Notification: {0}", args.Notification);
});

// To stop listening:
notification.Dispose ();

//
//Method style
//
NSObject notification;
void Callback (object sender, Foundation.NSNotificationEventArgs args)
{
    // Access strongly typed args
    Console.WriteLine ("Notification: {0}", args.Notification);
}

void Setup ()
{
    notification = UIScreen.Notifications.ObserveModeDidChange (Callback);
}

void Teardown ()
{
    notification.Dispose ();
}

Se aplica a

ObserveModeDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la ModeDidChangeNotification constante.

public static Foundation.NSObject ObserveModeDidChange (Foundation.NSObject objectToObserve, EventHandler<Foundation.NSNotificationEventArgs> handler);
static member ObserveModeDidChange : Foundation.NSObject * EventHandler<Foundation.NSNotificationEventArgs> -> Foundation.NSObject

Parámetros

objectToObserve
NSObject

Objeto que se va a observar.

handler
EventHandler<NSNotificationEventArgs>

Método que se invoca cuando se publica la notificación.

Devoluciones

Objeto token que se puede usar para dejar de recibir notificaciones mediante su eliminación o su paso a RemoveObservers(IEnumerable<NSObject>)

Comentarios

Este método se puede usar para suscribirse ModeDidChangeNotification a las notificaciones.

// Listen to all notifications posted for any object
var token = UIScreen.Notifications.ObserveModeDidChange ((notification) => {
	Console.WriteLine ("Observed ModeDidChangeNotification!");
};

// Listen to all notifications posted for a single object
var token = UIScreen.Notifications.ObserveModeDidChange (objectToObserve, (notification) => {
	Console.WriteLine ($"Observed ModeDidChangeNotification for {nameof (objectToObserve)}!");
};

// Stop listening for notifications
token.Dispose ();

Se aplica a