如何解开嵌套的IObservable

I am trying to create an IObservable<string> from the following code, but i can't seem to find a way of how to properly unwrap the value of the event handler.

发生的事情是,PasswordBox可能会更改,因此,每当要更改密码时,我都希望观察它,并在发生密码更改事件时提供字符串资源。如果我对普通事件进行处理,效果很好,但我对使用System.Reactive如何工作感到好奇。

        var passwordChanged = WhenPropertyChanged
            .Where(name => nameof(PasswordBox) == name)
            .Select(d => PasswordBox)
            .Where(d => d != null)
            .Select(box =>
            {
                return Observable.FromEvent<RoutedEventHandler, RoutedEventArgs>(
                    handler => box.PasswordChanged += handler,
                    handler => box.PasswordChanged -= handler);
            }).Select(d => nameof(Password));

to me it seems like there has to be some way within the Select(box => ... part where i can return a different object (other than IObservable<IObservable<RoutedEventArgs>>), which can be used to subscribe to properly.

像下面的作品那样做。但是我认为如果您端到端使用它,反应式在避免事件处理程序内存泄漏方面做得更好。

        var passwordHasChanged = new Subject<string>();
        // listen for changes of the password
        WhenPropertyChanged
            .Where(name => nameof(PasswordBox) == name)
            .Select(d => PasswordBox)
            .Where(d => d != null)
            .Subscribe(box =>
            {
                box.PasswordChanged += (sender, args) => passwordHasChanged.OnNext(nameof(Password));
            });

        passwordHasChanged.Subscribe(d => Log.Debug("Password changed"));