Наследование: Windows.UI.Xaml.Controls.ContentControl
Пример #1
0
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _layoutRoot = GetTemplateChild(LayoutRootPanelName) as Panel;
            _webView = (WebView)GetTemplateChild(WebViewName);
            _webViewBrush = GetTemplateChild(WebViewBrushName) as WebViewBrush;
            _addressBar = GetTemplateChild(AddressBarName) as TextBox;
            _titleBar = GetTemplateChild(TitleTextBlockName) as TextBlock;
            _favIconImage = GetTemplateChild(FavIconImageName) as Image;
            _progressIndicator = GetTemplateChild(ProgressIndicatorName) as ProgressBar;
            _backButton = GetTemplateChild(BackButtonName) as Button;
            _forwardButton = GetTemplateChild(ForwardButtonName) as Button;
            _goButton = GetTemplateChild(GoButtonName) as Button;
            _stopButton = GetTemplateChild(StopButtonName) as Button;
            _refreshButton = GetTemplateChild(RefreshButtonName) as Button;
            _addressAppBar = GetTemplateChild(AddressAppBarName) as CustomAppBar;
            _titleAppBar = GetTemplateChild(TitleAppBarName) as CustomAppBar;
            
            VisualStateManager.GoToState(this, AddressBarUnfocusedStateName, true);

            if (_addressBar != null)
            {
                _addressBar.KeyDown += OnAddressBarKeyDown;
                _addressBar.KeyUp += OnAddressBarKeyUp;
                _addressBar.GotFocus += OnAddressBarGotFocus;
                _addressBar.LostFocus += OnAddressBarLostFocus;
                _addressBar.TextChanged += OnAddressBarTextChanged;
            }

            if (_backButton != null)
            {
                _backButton.IsEnabled = false;
                _backButton.Click += OnBackButtonClick;
            }
            if (_forwardButton != null)
            {
                _forwardButton.IsEnabled = false;
                _forwardButton.Click += OnForwardButtonClick;
            }
            if (_goButton != null)
            {
                //_goButton.IsEnabled = false;
                _goButton.Click += OnGoButtonClick;
            }
            if (_stopButton != null)
            {
                _stopButton.IsEnabled = false;
                _stopButton.Click += OnStopButtonClick;
            }
            if (_refreshButton != null)
            {
                _refreshButton.IsEnabled = false;
                _refreshButton.Click += OnRefreshButtonClick;
            }
            if (_addressAppBar != null)
            {
                _addressAppBar.Opened += OnAppBarOpenedOrClosed;
                _addressAppBar.Closed += OnAppBarOpenedOrClosed;
            }
            if (_titleAppBar != null)
            {
                _titleAppBar.Opened += OnAppBarOpenedOrClosed;
                _titleAppBar.Closed += OnAppBarOpenedOrClosed;
            }

            _webView.NavigationCompleted += OnNavigationCompleted;

            if (this.Source != null)
            {
                _webView.Source = this.Source;
            }
            else
            {
                this.Source = _webView.Source;
            }

            if (_pendingNavigation)
            {
                Navigate(this.Source);
            }
        }
Пример #2
0
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding layout pass) call ApplyTemplate. In simplest terms, this means the method is called just before a UI element displays in your app. Override this method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            _layoutRoot        = GetTemplateChild(LayoutRootPanelName) as Panel;
            _webView           = (WebView)GetTemplateChild(WebViewName);
            _webViewBrush      = GetTemplateChild(WebViewBrushName) as WebViewBrush;
            _addressBar        = GetTemplateChild(AddressBarName) as TextBox;
            _titleBar          = GetTemplateChild(TitleTextBlockName) as TextBlock;
            _favIconImage      = GetTemplateChild(FavIconImageName) as Image;
            _progressIndicator = GetTemplateChild(ProgressIndicatorName) as ProgressBar;
            _backButton        = GetTemplateChild(BackButtonName) as Button;
            _forwardButton     = GetTemplateChild(ForwardButtonName) as Button;
            _goButton          = GetTemplateChild(GoButtonName) as Button;
            _stopButton        = GetTemplateChild(StopButtonName) as Button;
            _refreshButton     = GetTemplateChild(RefreshButtonName) as Button;
            _addressAppBar     = GetTemplateChild(AddressAppBarName) as CustomAppBar;
            _titleAppBar       = GetTemplateChild(TitleAppBarName) as CustomAppBar;

            VisualStateManager.GoToState(this, AddressBarUnfocusedStateName, true);

            if (_addressBar != null)
            {
                _addressBar.KeyDown     += OnAddressBarKeyDown;
                _addressBar.KeyUp       += OnAddressBarKeyUp;
                _addressBar.GotFocus    += OnAddressBarGotFocus;
                _addressBar.LostFocus   += OnAddressBarLostFocus;
                _addressBar.TextChanged += OnAddressBarTextChanged;
            }

            if (_backButton != null)
            {
                _backButton.IsEnabled = false;
                _backButton.Click    += OnBackButtonClick;
            }
            if (_forwardButton != null)
            {
                _forwardButton.IsEnabled = false;
                _forwardButton.Click    += OnForwardButtonClick;
            }
            if (_goButton != null)
            {
                //_goButton.IsEnabled = false;
                _goButton.Click += OnGoButtonClick;
            }
            if (_stopButton != null)
            {
                _stopButton.IsEnabled = false;
                _stopButton.Click    += OnStopButtonClick;
            }
            if (_refreshButton != null)
            {
                _refreshButton.IsEnabled = false;
                _refreshButton.Click    += OnRefreshButtonClick;
            }
            if (_addressAppBar != null)
            {
                _addressAppBar.Opened += OnAppBarOpenedOrClosed;
                _addressAppBar.Closed += OnAppBarOpenedOrClosed;
            }
            if (_titleAppBar != null)
            {
                _titleAppBar.Opened += OnAppBarOpenedOrClosed;
                _titleAppBar.Closed += OnAppBarOpenedOrClosed;
            }

            _webView.NavigationCompleted += OnNavigationCompleted;

            if (this.Source != null)
            {
                _webView.Source = this.Source;
            }
            else
            {
                this.Source = _webView.Source;
            }

            if (_pendingNavigation)
            {
                Navigate(this.Source);
            }
        }