コード例 #1
0
        protected override void OnViewLoaded(object view)
        {
            const int Feature             = 21; //FEATURE_DISABLE_NAVIGATION_SOUNDS
            const int SetFeatureOnProcess = 0x00000002;

            base.OnViewLoaded(view);

            var typedView = view as MessageDetailHtmlView;

            if (typedView == null)
            {
                _logger.Error("Unable to locate the MessageDetailHtmlView to hook the WebBrowser Control");
                return;
            }

            try
            {
                // disable the stupid click sound on navigate
                var enabled = CoInternetSetFeatureEnabled(Feature, SetFeatureOnProcess, true);
            }
            catch (Exception ex)
            {
                // just have to live with the sound
                _logger.Warning(ex, "Failed to disable the Navigation Sounds on the WebBrowser control");
            }

            this.GetPropertyValues(p => p.HtmlFile)
            .Subscribe(
                file =>
            {
                typedView.htmlView.Source = new Uri(string.IsNullOrWhiteSpace(file) ? "about:blank" : file);
            });

            Observable.FromEvent <DependencyPropertyChangedEventHandler, DependencyPropertyChangedEventArgs>(
                a => ((s, e) => a(e)),
                h => typedView.IsEnabledChanged += h,
                h => typedView.IsEnabledChanged -= h)
            .Throttle(TimeSpan.FromMilliseconds(100))
            .ObserveOnDispatcher()
            .Subscribe(
                o =>
            {
                typedView.htmlView.Visibility = o.NewValue.ToType <bool>()
                                                            ? Visibility.Visible
                                                            : Visibility.Collapsed;
            });

            typedView.htmlView.Navigated += (sender, args) =>
            {
                BrowserHandler.SetSilent(typedView.htmlView, true);
            };
        }