Esempio n. 1
0
        /// <summary>
        /// event from thumbnail list to swap out selected tech panel
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">event parameter</param>
        private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // ensure the tech is no longer parented and selected property is false
            if (this.lastSelectedTech != null)
            {
                var parent = this.lastSelectedTech.DXPanel.Parent as Panel;
                if (parent != null)
                {
                    parent.Children.Remove(this.lastSelectedTech.DXPanel);
                }
                else
                {
                    var border = this.lastSelectedTech.DXPanel.Parent as Border;
                    border.Child = null;
                }

                // trigger the property change
                this.lastSelectedTech.IsSelected = false;
            }

            DXSwapPanel tech = Thumbnails.SelectedItem as DXSwapPanel;

            if (tech != null)
            {
                // trigger the property change
                tech.IsSelected = true;

                // parent the selected control to the main UI
                var parent = tech.DXPanel.Parent as Panel;
                if (parent != null)
                {
                    parent.Children.Remove(tech.DXPanel);
                }
                else
                {
                    var border = tech.DXPanel.Parent as Border;
                    if (border != null)
                    {
                        border.Child = null;
                    }
                }

                // parent the panel to large view
                if (DXSwapPanel.Type.Tech == tech.PanelType)
                {
                    TechPreview.Child = tech.DXPanel;
                }
            }

            // track this as the last selected item
            if (tech != null)
            {
                this.lastSelectedTech = tech;
            }
            else
            {
                this.Thumbnails.SelectedIndex = this.lastSelectedTechIndex;
            }
        }
        /// <summary>
        /// handles data context changes
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="args">passed parameter values for the event</param>
        private void OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            DXSwapPanel panel = args.NewValue as DXSwapPanel;

            if (this.swapPanel != panel)
            {
                // unsubscribe to previous event changes
                if (panel != null && this.swapPanel != null)
                {
                    this.swapPanel.PropertyChanged -= this.OnPropertyChanged;
                }

                this.swapPanel = panel;

                // subscribe to the n
                if (this.swapPanel != null)
                {
                    this.swapPanel.PropertyChanged += this.OnPropertyChanged;
                }

                if (!this.swapPanel.IsSelected)
                {
                    // ensure control is not parented
                    var parent = this.swapPanel.DXPanel.Parent as Panel;
                    if (parent != null)
                    {
                        parent.Children.Remove(this.swapPanel.DXPanel);
                    }
                    else
                    {
                        var border = this.swapPanel.DXPanel.Parent as Border;
                        if (border != null)
                        {
                            border.Child = null;
                        }
                    }

                    ParentGrid.Children.Add(this.swapPanel.DXPanel);
                }
            }
        }