Пример #1
0
        /// <summary>
        /// Occurs when the element is laid out, rendered, and ready for interaction.
        /// </summary>
        /// <param name="sender">The object where the event handler is attached.</param>
        /// <param name="e">The event data.</param>
        void OnLoaded(Object sender, RoutedEventArgs e)
        {
            // The GadgetBar is actually not part of the ExplorerPage even though its resources are declared here.  When the ExplorerPage is hooked into the
            // ExplorerFrame, the frame gets a message asking it to use the GadgetBar (which is really just an ObservableCollection of Gadgets) as the ItemsSource
            // in the ExplorerBar control on the frame.  So The GadgetBar property in this control is really just a collection that is used by the main frame window
            // of the application.  As such, it has no way of routing commands back to the ExplorerPage where the Gadget was declared.  If we left the CommandTarget
            // alone, the Command Routing would attempt to find the element with the focus, but that is too random for most high level, application-type commands.
            // This will direct every Gadget with a command, that has a corresponding CommandBinding, to target this page when the command is invoked.
            foreach (Gadget gadget in this.GadgetBar)
            {
                foreach (CommandBinding commandBinding in this.CommandBindings)
                {
                    if (gadget.Command == commandBinding.Command && gadget.CommandTarget == null)
                    {
                        gadget.CommandTarget = this;
                    }
                }
            }

            // The data context for the page is the item selected in the frame.
            ExplorerFrame explorerFrame = VisualTreeExtensions.FindAncestor <ExplorerFrame>(this);

            if (explorerFrame != null)
            {
                this.DataContext = explorerFrame.SelectedItem;
            }

            // This will send a message up to the frame that there is a new set of gadgets available.  The frame will use this instance's collection directly so
            // that changing the local collection here will change the way the gadgets are displayed in the frame's toolbar.
            if (this.GadgetBar.Count != 0)
            {
                this.RaiseEvent(new ItemsSourceEventArgs(ExplorerFrame.GadgetBarChangedEvent, this.GadgetBar));
            }
        }
Пример #2
0
        /// <summary>
        /// Called when the parent of the visual MenuItem changes.
        /// </summary>
        /// <param name="oldParent">Old value of the parent of the visual, or null if the visual did not have a parent.</param>
        protected override void OnVisualParentChanged(DependencyObject oldParent)
        {
            // This control will automatically bind to properties on a TreeFrame.  However, the control may be moved from one parent to the next, such as when it
            // moves from the overflow panel back to the main tool bar.  To handle the fact that the visual tree can change, this method is need to disconnect
            // the control when it is in limbo and reconnect it when it's found a new home.
            ExplorerFrame explorerFrame = VisualTreeExtensions.FindAncestor <ExplorerFrame>(this);

            if (explorerFrame == null)
            {
                // Disconnect the bindings to the ancestor TreeFrame when the control is floating without a TreeFrame ancestor.
                BindingOperations.ClearBinding(this, ViewButton.ViewValueProperty);
                BindingOperations.ClearBinding(this, ViewButton.ViewModeProperty);
            }
            else
            {
                // This will automatically connect the Value property to the ancestor TreeView when it's found a new home.
                Binding viewValueBinding = new Binding();
                viewValueBinding.Path   = new PropertyPath("ViewValue");
                viewValueBinding.Source = explorerFrame;
                viewValueBinding.Mode   = BindingMode.TwoWay;
                BindingOperations.SetBinding(this, ViewButton.ViewValueProperty, viewValueBinding);
            }

            // Allow the base class to handle the rest of the event.
            base.OnVisualParentChanged(oldParent);
        }
Пример #3
0
        /// <summary>
        /// Occurs when the element is laid out, rendered, and ready for interaction.
        /// </summary>
        /// <param name="sender">The object where the event handler is attached.</param>
        /// <param name="routedEventArgs">The event data.</param>
        void OnLoaded(Object sender, RoutedEventArgs routedEventArgs)
        {
            // This object will automatically bind itself to a parent TreeFrame when one is available.
            ExplorerFrame explorerFrame = VisualTreeExtensions.FindAncestor <ExplorerFrame>(this);

            if (explorerFrame != null)
            {
                // The children of a Frame do not automatically inherit the data context of the parent window.  This is likely due to the fact that pages are not
                // naturally kept alive when the navigation moves away.  So any data binding operation must be established or re-established when the page is
                // loaded and must be cleared when the page is unloaded.  This will bind this page to the context of the parent frame (for now).
                Binding dataContextBinding = new Binding();
                dataContextBinding.Path   = new PropertyPath("DataContext");
                dataContextBinding.Source = explorerFrame;
                dataContextBinding.Mode   = BindingMode.OneWay;
                BindingOperations.SetBinding(this, ViewPage.DataContextProperty, dataContextBinding);

                // The Source property binding allows a change to the property to propogate up to the container.
                Binding sourceBinding = new Binding();
                sourceBinding.Path   = new PropertyPath("Source");
                sourceBinding.Source = explorerFrame;
                sourceBinding.Mode   = BindingMode.TwoWay;
                BindingOperations.SetBinding(this, ViewPage.SourceProperty, sourceBinding);

                // This value indicates what kind of view is used to display the items.
                Binding viewValueBinding = new Binding();
                viewValueBinding.Path   = new PropertyPath("ViewValue");
                viewValueBinding.Source = explorerFrame;
                viewValueBinding.Mode   = BindingMode.TwoWay;
                BindingOperations.SetBinding(this, ViewPage.ViewValueProperty, viewValueBinding);
            }
        }
Пример #4
0
 private void HomeButton_Click(object sender, RoutedEventArgs e)
 {
     //if (FrameHistory[FrameHistoryIndex] != ExplorerPage.ExploreMangaPage)
     //{
     App.CancellationToken.Cancel();
     ExplorerFrame.Navigate(new MangaExplorerPage());
     //}
 }
Пример #5
0
 private void NextButton_Click(object sender, RoutedEventArgs e)
 {
     if (ExplorerFrame.CanGoForward)
     {
         App.CancellationToken.Cancel();
         ExplorerFrame.GoForward();
         FrameHistoryIndex++;
     }
 }
Пример #6
0
 private void BackButton_Click(object sender, RoutedEventArgs e)
 {
     if (ExplorerFrame.CanGoBack)
     {
         App.CancellationToken.Cancel();
         ExplorerFrame.GoBack();
         FrameHistoryIndex--;
     }
 }
Пример #7
0
            internal void SetExplorerInfo(ExplorerFrame explorerFrame, SelectionContainer <ExplorerSelection> selectionContainer)
            {
                _explorerFrame      = explorerFrame;
                _selectionContainer = selectionContainer;

                var context = explorerFrame.Context;

                context.Disposing += OnContextDisposing;
                context.Items.SetValue(this);
            }
Пример #8
0
            private void OnContextDisposing(object sender, EventArgs e)
            {
                var context = (EditingContext)sender;

                if (_selectionContainer != null)
                {
                    _selectionContainer.Dispose();
                    _selectionContainer = null;
                }

                if (_explorerFrame != null)
                {
                    _explorerFrame.Dispose();
                    _explorerFrame = null;
                }

                context.Items.SetValue(new ExplorerInfo());
                context.Disposing -= OnContextDisposing;
            }
Пример #9
0
        public MainWindow()
        {
            InitializeComponent();
            FavoriteMangaList.ItemsSource = ObservableFavoriteMangas;


            NavigationFrame   = ExplorerFrame;
            FrameHistoryIndex = -1;
            FrameHistory      = new List <ExplorerPage>();
            //Frame.CacheMode = null;
            navigationService = ExplorerFrame.NavigationService;

            //ExplorerFrame.Source = new Uri("Explorer.xaml");
            //Debug.WriteLine("Frame source: " + ExplorerFrame.Source);
            if (App.FIRST_MANGA_GRAB)
            {
                App.FIRST_MANGA_GRAB = !App.FIRST_MANGA_GRAB;
                //Task.Run(() => UpdateMangaDB());
                Task.Factory.StartNew(() => UpdateMangaDB(), TaskCreationOptions.LongRunning);          // Better way of doing it for long running task
            }
            Task.Run(() => RefreshFavorites());
            ExplorerFrame.Navigate(new MangaExplorerPage());
        }