Esempio n. 1
0
 private static UIElement r_2_ctMethod(UIElement parent)
 {
     // e_0 element
     Grid e_0 = new Grid();
     e_0.Parent = parent;
     e_0.Name = "e_0";
     RowDefinition row_e_0_0 = new RowDefinition();
     row_e_0_0.Height = new GridLength(20F, GridUnitType.Pixel);
     e_0.RowDefinitions.Add(row_e_0_0);
     RowDefinition row_e_0_1 = new RowDefinition();
     e_0.RowDefinitions.Add(row_e_0_1);
     // PART_WindowTitleBorder element
     Border PART_WindowTitleBorder = new Border();
     e_0.Children.Add(PART_WindowTitleBorder);
     PART_WindowTitleBorder.Name = "PART_WindowTitleBorder";
     PART_WindowTitleBorder.Background = new SolidColorBrush(new ColorW(255, 255, 255, 255));
     // e_1 element
     ContentPresenter e_1 = new ContentPresenter();
     e_0.Children.Add(e_1);
     e_1.Name = "e_1";
     Grid.SetRow(e_1, 1);
     Binding binding_e_1_Content = new Binding();
     e_1.SetBinding(ContentPresenter.ContentProperty, binding_e_1_Content);
     return e_0;
 }
Esempio n. 2
0
        /// <summary>
        /// Overrides the default behavior when the control template is applied.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            transformRoot = GetTemplateChild( TransformRootName ) as Grid;
            contentPresenter = GetTemplateChild( PresenterName ) as ContentPresenter;
            renderTransform = new MatrixTransform();

            if ( transformRoot != null )
                transformRoot.RenderTransform = renderTransform;

            ApplyLayoutTransform();
        }
Esempio n. 3
0
        // Be sure to call the base class constructor.
        public DragAdorner(TreeViewEx treeViewEx, DragContent content)
            : base(treeViewEx)
        {
            layer = AdornerLayer.GetAdornerLayer(treeViewEx);
            layer.Add(this);

            contentPresenter = new ContentPresenter();
            contentPresenter.Content = content;

            Binding b = new Binding("DragTemplate");
            b.Source = treeViewEx;
            b.Mode = BindingMode.OneWay;
            contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, b);
        }
        public void OnPostInit()
        {
            var templateRoot = VisualTreeHelper.GetChild(this, 0) as FrameworkElement;
            this.contentPresenter = (ContentPresenter)templateRoot.FindName("ContentPresenter");
            this.contentPresenterScaleTransform = new ScaleTransform(1f, 1f);
            this.contentPresenter.RenderTransform = this.contentPresenterScaleTransform;

            this.Loaded += this.OnLoaded;

            // just for testing
            Instances.Add(new WeakReference(this));

            this.RefreshViewBoxMargins();
        }
Esempio n. 5
0
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();

			var listener = GestureService.GetGestureListener(this);
			listener.PinchStarted += OnPinchStarted;
			listener.PinchDelta += OnPinchDelta;
			listener.DragDelta += OnDragDelta;			
#endif

			content = (ContentPresenter)GetTemplateChild("content");
			if (content.Content == null)
				content.Content = Content;
			
			geometry = new RectangleGeometry();
			Clip = geometry;

			SizeChanged += delegate { UpdateGeometry(); };
			UpdateGeometry();
		}
Esempio n. 6
0
        public InsertAdorner(TreeViewExItem treeViewItem, InsertContent content)
            : base(GetParentBorder(treeViewItem))
        {
            this.treeViewItem = treeViewItem;

            layer = AdornerLayer.GetAdornerLayer(AdornedElement);
            layer.Add(this);

            contentPresenter = new ContentPresenter();
            contentPresenter.HorizontalAlignment = HorizontalAlignment.Stretch;
            contentPresenter.Width = treeViewItem.ActualWidth;
            contentPresenter.Content = content;

            Binding b = new Binding("InsertTemplate");
            b.Source = treeViewItem.ParentTreeView;
            b.Mode = BindingMode.OneWay;
            contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, b);

            content.InsertionMarkerBrush = treeViewItem.ParentTreeView.InsertionMarkerBrush;
            content.Item = treeViewItem;
        }
Esempio n. 7
0
        protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            int  xparticles = 15, yparticles = 15;
            Size size = transitionElement.RenderSize;

            if (size.Width > size.Height)
            {
                yparticles = (int)(xparticles * size.Height / size.Width);
            }
            else
            {
                xparticles = (int)(yparticles * size.Width / size.Height);
            }

            MeshGeometry3D mesh       = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), xparticles - 1, yparticles - 1, new Rect(0, 0, 1, 1));
            Brush          cloneBrush = CreateBrush(oldContent);
            Material       clone      = new DiffuseMaterial(cloneBrush);

            double ustep = size.Width / (xparticles - 1), vstep = size.Height / (yparticles - 1);

            Point3DCollection points = mesh.Positions;

            Random rand = new Random();

            // add some random movement to the z order
            for (int i = 0; i < points.Count; i++)
            {
                points[i] += 0.1 * ustep * (rand.NextDouble() * 2 - 1) * new Vector3D(0, 0, 1);
            }

            Point3DCollection oldPoints = points.Clone();

            Vector3D        acceleration = new Vector3D(0, 700, 0); //gravity
            double          timeStep     = 1.0 / 60.0;
            DispatcherTimer timer        = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(timeStep);
            bool   fading        = false;
            double time          = 0;
            double slideVelocity = size.Width / 2.0;
            double windScale     = 30 * size.Width * size.Height;

            timer.Tick += delegate
            {
                time = time + timeStep;
                Point   mousePos   = Mouse.GetPosition(viewport);
                Point3D mousePos3D = new Point3D(mousePos.X, mousePos.Y, -10);

                // Cloth physics based on work of Thomas Jakobsen http://www.teknikus.dk/tj/gdc2001.htm
                for (int i = 0; i < oldPoints.Count; i++)
                {
                    Point3D  currentPoint = points[i];
                    Vector3D wind         = new Vector3D(0, 0, windScale / (mousePos3D - currentPoint).LengthSquared);
                    Point3D  newPoint     = currentPoint + (currentPoint - oldPoints[i]) + timeStep * timeStep * (acceleration + wind);

                    if (newPoint.Y > size.Height)
                    {
                        newPoint.Y = size.Height;
                    }

                    oldPoints[i] = newPoint;
                }

                //for (int j = 0; j < 5; j++)
                for (int i = oldPoints.Count - 1; i > 0; i--)
                {
                    // constrain with point to the left
                    if (i > yparticles)
                    {
                        Constrain(oldPoints, i, i - yparticles, ustep);
                    }
                    // constrain with point to the top
                    if (i % yparticles != 0)
                    {
                        Constrain(oldPoints, i, i - 1, vstep);
                    }
                }

                // slide the top row of points to the left
                for (int i = 0; i < xparticles; i += 1)
                {
                    oldPoints[i * yparticles] = new Point3D(Math.Max(0, i * ustep - slideVelocity * time * i / (xparticles - 1)), 0, 0);
                }

                if (!fading && points[points.Count - yparticles].X < size.Width / 2)
                {
                    fading = true;
                    DoubleAnimation da = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(1.5)));
                    da.Completed += delegate
                    {
                        timer.Stop();
                        EndTransition(transitionElement, oldContent, newContent);
                    };
                    cloneBrush.BeginAnimation(Brush.OpacityProperty, da);
                }

                // Swap position arrays
                mesh.Positions = oldPoints;
                oldPoints      = points;
                points         = mesh.Positions;
            };
            timer.Start();


            GeometryModel3D geo = new GeometryModel3D(mesh, clone);

            geo.BackMaterial = clone;
            ModelVisual3D model = new ModelVisual3D();

            model.Content = geo;
            viewport.Children.Add(model);
        }
Esempio n. 8
0
        protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            int  xparticles = 10, yparticles = 10;
            Size size = transitionElement.RenderSize;

            if (size.Width > size.Height)
            {
                yparticles = (int)(xparticles * size.Height / size.Width);
            }
            else
            {
                xparticles = (int)(yparticles * size.Width / size.Height);
            }

            MeshGeometry3D mesh       = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), xparticles - 1, yparticles - 1, new Rect(0, 0, 1, 1));
            Brush          cloneBrush = CreateBrush(oldContent);
            Material       clone      = new DiffuseMaterial(cloneBrush);

            double ustep = size.Width / (xparticles - 1), vstep = size.Height / (yparticles - 1);

            Point3DCollection points = mesh.Positions;

            Point3DCollection oldPoints = points.Clone();

            double          timeStep = 1.0 / 30.0;
            DispatcherTimer timer    = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(timeStep);
            double time     = 0;
            double duration = 2;

            timer.Tick += delegate
            {
                time = time + timeStep;
                Point   mousePos   = Mouse.GetPosition(viewport);
                Point3D mousePos3D = new Point3D(mousePos.X, mousePos.Y, -10);

                // Cloth physics based on work of Thomas Jakobsen http://www.ioi.dk/~thomas
                for (int i = 0; i < oldPoints.Count; i++)
                {
                    Point3D currentPoint = points[i];
                    Point3D newPoint     = currentPoint + 0.9 * (currentPoint - oldPoints[i]);

                    if (newPoint.Y > size.Height)
                    {
                        newPoint.Y = size.Height;
                    }

                    oldPoints[i] = newPoint;
                }

                for (int a = yparticles - 1; a >= 0; a--)
                {
                    for (int b = xparticles - 1; b >= 0; b--)
                    {
                        int i = b * yparticles + a;
                        // constrain with point to the left
                        if (i > yparticles)
                        {
                            Constrain(oldPoints, i, i - yparticles, ustep);
                        }
                        // constrain with point to the top
                        if (i % yparticles != 0)
                        {
                            Constrain(oldPoints, i, i - 1, vstep);
                        }

                        // constrain the sides
                        if (a == 0)
                        {
                            oldPoints[i] = new Point3D(oldPoints[i].X, 0, oldPoints[i].Z);
                        }
                        if (a == yparticles - 1)
                        {
                            oldPoints[i] = new Point3D(oldPoints[i].X, size.Height, oldPoints[i].Z);
                        }

                        if (b == 0)
                        {
                            oldPoints[i] = new Point3D(0, a * size.Height / (yparticles - 1), 0);
                        }

                        if (b == xparticles - 1)
                        {
                            double angle = time / duration * Math.PI / (0.8 + 0.5 * (yparticles - (double)a) / yparticles);
                            oldPoints[i] = new Point3D(size.Width * Math.Cos(angle), a * size.Height / (yparticles - 1), -size.Width * Math.Sin(angle));
                        }
                    }
                }

                if (time > (duration - 0))
                {
                    timer.Stop();
                    EndTransition(transitionElement, oldContent, newContent);
                }

                // Swap position arrays
                mesh.Positions = oldPoints;
                oldPoints      = points;
                points         = mesh.Positions;
            };
            timer.Start();

            GeometryModel3D geo = new GeometryModel3D(mesh, clone);

            geo.BackMaterial = clone;
            ModelVisual3D model = new ModelVisual3D();

            model.Content = geo;
            viewport.Children.Add(model);
        }
Esempio n. 9
0
#pragma warning disable 4014
        /// <summary>
        /// When overridden in a derived class, is invoked whenever application code or internal processes (such as a rebuilding layout pass) call <see cref="M:System.Windows.Controls.Control.ApplyTemplate" />. In simplest terms, this means the method is called just before a UI element displays in an application. For more information, see Remarks.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            // For some reason GetTemplateChild does not find animation declared in a VisualState.
            var layoutRoot = this.GetTemplateChild("PART_LayoutRoot") as Border;

            this.contentHolder = this.GetTemplateChild("PART_ExpandableContentHolder") as Canvas;
            var expandedVisualState = VisualStateManager.GetVisualStateGroups(layoutRoot)[0].States.First(state => state.Name == "Expanded");

            if (expandedVisualState != null && expandedVisualState.Storyboard != null)
            {
                var animation = new DoubleAnimation();
                animation.Duration = new Duration(TimeSpan.FromSeconds(0));
                animation.EnableDependentAnimation = true;
                Storyboard.SetTarget(animation, this.contentHolder);
                animation.SetValue(Storyboard.TargetPropertyProperty, "Height");
                this.expandContentHolderAnimation = animation;

                expandedVisualState.Storyboard.Children.Add(this.expandContentHolderAnimation);
            }

            base.OnApplyTemplate();

            this.expanderHeaderLayoutRoot       = this.GetTemplateChild("PART_ExpanderHeaderLayoutRoot") as Panel;
            this.mainContentPresenter           = this.GetTemplateChild("PART_MainContentPresenter") as ContentPresenter;
            this.expandableContent              = this.GetTemplateChild("PART_ExpandableContentPresenter") as ContentPresenter;
            this.expandableContent.SizeChanged += this.OnExpandableContentPresenter_SizeChanged;
            this.contentHolder.SizeChanged     += this.OnContentHolder_SizeChanged;
            this.expandAnimation   = this.GetTemplateChild("PART_ExpandAnimation") as DoubleAnimation;
            this.animatedIndicator = this.GetTemplateChild("PART_AnimatedIndicator") as ContentPresenter;

            Binding b = new Binding();

            b.Source            = this;
            b.Path              = new PropertyPath("DataContext");
            this.contextBinding = true;
            this.SetBinding(DataContextPrivateProperty, b);
            this.contextBinding = false;

            if (this.IsProperlyTemplated)
            {
                if (!this.IsExpandable && this.HideIndicatorWhenNotExpandable)
                {
                    this.animatedIndicator.Visibility = Visibility.Collapsed;
                }
                else
                {
                    this.animatedIndicator.Visibility = Visibility.Visible;
                }

                if (DesignMode.DesignModeEnabled)
                {
                    this.SetInitialControlState(false);
                }
                else
                {
                    this.Dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal,
                        () =>
                    {
                        this.SetInitialControlState(false);
                    });
                }
            }
        }
Esempio n. 10
0
 public LinkUnlinkEventArgs(ContentPresenter contentPresenter)
 {
     this.ContentPresenter = contentPresenter;
 }
Esempio n. 11
0
        protected internal override void BeginTransition(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
        {
            DoubleAnimation da = new DoubleAnimation(0, Duration);

            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            oldContent.BeginAnimation(UIElement.OpacityProperty, da);
        }
Esempio n. 12
0
        private static void CreateDragAdorner()
        {
            var template         = GetDragAdornerTemplate(m_DragInfo.VisualSource);
            var templateSelector = GetDragAdornerTemplateSelector(m_DragInfo.VisualSource);

            UIElement adornment = null;

            var useDefaultDragAdorner = GetUseDefaultDragAdorner(m_DragInfo.VisualSource);

            if (template == null && templateSelector == null && useDefaultDragAdorner)
            {
                var bs = CaptureScreen(m_DragInfo.VisualSourceItem, m_DragInfo.VisualSourceFlowDirection);
                if (bs != null)
                {
                    var factory = new FrameworkElementFactory(typeof(Image));
                    factory.SetValue(Image.SourceProperty, bs);
                    factory.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);
                    factory.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.HighQuality);
                    factory.SetValue(FrameworkElement.WidthProperty, bs.Width);
                    factory.SetValue(FrameworkElement.HeightProperty, bs.Height);
                    factory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                    factory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Top);
                    template = new DataTemplate {
                        VisualTree = factory
                    };
                }
            }

            if (template != null || templateSelector != null)
            {
                if (m_DragInfo.Data is IEnumerable && !(m_DragInfo.Data is string))
                {
                    if (!useDefaultDragAdorner && ((IEnumerable)m_DragInfo.Data).Cast <object>().Count() <= 10)
                    {
                        var itemsControl = new ItemsControl();
                        itemsControl.ItemsSource          = (IEnumerable)m_DragInfo.Data;
                        itemsControl.ItemTemplate         = template;
                        itemsControl.ItemTemplateSelector = templateSelector;

                        // The ItemsControl doesn't display unless we create a border to contain it.
                        // Not quite sure why this is...
                        var border = new Border();
                        border.Child = itemsControl;
                        adornment    = border;
                    }
                }
                else
                {
                    var contentPresenter = new ContentPresenter();
                    contentPresenter.Content                 = m_DragInfo.Data;
                    contentPresenter.ContentTemplate         = template;
                    contentPresenter.ContentTemplateSelector = templateSelector;
                    adornment = contentPresenter;
                }
            }

            if (adornment != null)
            {
                if (useDefaultDragAdorner)
                {
                    adornment.Opacity = GetDefaultDragAdornerOpacity(m_DragInfo.VisualSource);
                }

                var parentWindow = m_DragInfo.VisualSource.GetVisualAncestor <Window>();
                var rootElement  = parentWindow != null ? parentWindow.Content as UIElement : null;
                if (rootElement == null && Application.Current != null && Application.Current.MainWindow != null)
                {
                    rootElement = (UIElement)Application.Current.MainWindow.Content;
                }
                //                i don't want the fu... windows forms reference
                //                if (rootElement == null) {
                //                    var elementHost = m_DragInfo.VisualSource.GetVisualAncestor<ElementHost>();
                //                    rootElement = elementHost != null ? elementHost.Child : null;
                //                }
                if (rootElement == null)
                {
                    rootElement = m_DragInfo.VisualSource.GetVisualAncestor <UserControl>();
                }

                DragAdorner = new DragAdorner(rootElement, adornment);
            }
        }
        protected override void OnApplyTemplate()
        {
            _topAreaContent = base.GetTemplateChild("PART_TopArea") as ContentPresenter;
            _bottomAreaContent = base.GetTemplateChild("PART_BottomArea") as ContentPresenter;
            _mainCanvas = base.GetTemplateChild("PART_MainCanvas") as Canvas;

            _closeBottomContentStoryboard =
                _mainCanvas.Resources["CloseBottomContentStoryboard"]
                    as Storyboard;

            _openBottomContentStoryboard = _mainCanvas.Resources["OpenBottomContentStoryboard"] as Storyboard;

            _openAnimation = _openBottomContentStoryboard.Children[0] as DoubleAnimation;
            _closeAnimation = _closeBottomContentStoryboard.Children[0] as DoubleAnimation;

            Loaded -= OnBottomSlideContentPresenterLoaded;
            Loaded += OnBottomSlideContentPresenterLoaded;

            SubscribeForEventListenerEvents();

            base.OnApplyTemplate();
        }
Esempio n. 14
0
        public void OnVisibilityChanged(TabContentVisibilityEvent visEvent)
        {
            var ev = Convert(visEvent);

            if (ev != null)
            {
#if DEBUG
                switch (ev)
                {
                case ToolWindowContentVisibilityEvent.Added:
                    Debug.Assert(!_added);
                    Debug.Assert(!_visible);
                    _added = true;
                    break;

                case ToolWindowContentVisibilityEvent.Removed:
                    Debug.Assert(_added);
                    Debug.Assert(!_visible);
                    _added = false;
                    break;

                case ToolWindowContentVisibilityEvent.Visible:
                    Debug.Assert(_added);
                    Debug.Assert(!_visible);
                    _visible = true;
                    break;

                case ToolWindowContentVisibilityEvent.Hidden:
                    Debug.Assert(_added);
                    Debug.Assert(_visible);
                    _visible = false;
                    break;
                }
#endif
                if (moving && (visEvent == TabContentVisibilityEvent.Added || visEvent == TabContentVisibilityEvent.Removed))
                {
                    // Don't send the Added/Removed events
                    moving = false;
                }
                else
                {
                    content.OnVisibilityChanged(ev.Value);
                }
            }

            switch (visEvent)
            {
            case TabContentVisibilityEvent.Removed:
                elementScaler.Dispose();
                RemoveEvents();
                if (contentPresenter != null)
                {
                    contentPresenter.Content = null;
                }
                contentPresenter = null;
                OnPropertyChanged("UIObject");
                ContentUIObject = null;
                break;

            case TabContentVisibilityEvent.GotKeyboardFocus:
                IsActive = true;
                break;

            case TabContentVisibilityEvent.LostKeyboardFocus:
                IsActive = false;
                break;
            }
        }
Esempio n. 15
0
		internal void UpdateHeader()
		{
			if (!loaded)
				return; 

			if (HeaderTemplate == null)
			{
				if (headerPresenter != null)
				{
					if (Items.Contains(headerPresenter))
						Items.Remove(headerPresenter);
					headerPresenter = null;
				}
			}
			else
			{
				if (headerPresenter == null)
				{
					headerPresenter = new ContentPresenter();
					headerPresenter.Content = this.FindParentDataContext();
					headerPresenter.Visibility = ShowHeader ? Visibility.Visible : Visibility.Collapsed;
				}

				if (!Items.Contains(headerPresenter))
					Items.Insert(0, headerPresenter);

				headerPresenter.ContentTemplate = HeaderTemplate;
			}
		}
        public override void OnApplyTemplate()
        {
            Button closeButton = GetTemplateChild("btnCloseWindow") as Button;

            if (closeButton != null)
            {
                closeButton.Click += CloseClick;
            }

            Button cancelButton = GetTemplateChild("btnCancel") as Button;

            if (cancelButton != null)
            {
                cancelButton.Click += CancelClick;
            }

            Button okButton = GetTemplateChild("btnOk") as Button;

            if (okButton != null)
            {
                okButton.Click += OkClick;
            }

            titelBorder = GetTemplateChild("titelBorder") as Border;
            if (titelBorder != null)
            {
                titelBorder.Visibility = ShowTitelBorder;
            }

            Panel buttonsPanel = GetTemplateChild("buttonsPanel") as Panel;

            if (buttonsPanel != null)
            {
                buttonsPanel.Visibility = ShowButtonsPanel;
            }

            ScrollViewer contentScrollViewer = GetTemplateChild("svScrollViewer") as ScrollViewer;

            if (contentScrollViewer != null && !double.IsNaN(MaxContentHeight))
            {
                contentScrollViewer.MaxHeight = MaxContentHeight;
            }

            if (contentScrollViewer != null && !double.IsNaN(ScrollWidth))
            {
                contentScrollViewer.Width = ScrollWidth;
            }


            ContentPresenter headerContentPresenter = GetTemplateChild("HeaderContentPresenter") as ContentPresenter;

            if (headerContentPresenter != null)
            {
                headerContentPresenter.Content = TitelContent;
            }

            contentControl = GetTemplateChild("AddEditControl") as Panel;
            if (contentControl != null & !double.IsNaN(ContentWidth))
            {
                contentControl.Width = ContentWidth;
            }


            base.OnApplyTemplate();
        }
 public DropPreviewAdorner(UIElement feedbackUI, UIElement adornedElt) : base(adornedElt)
 {
     _presenter                  = new ContentPresenter();
     _presenter.Content          = feedbackUI;
     _presenter.IsHitTestVisible = false;
 }
        public override void OnApplyTemplate()
        {
            presenter = (ContentPresenter)GetTemplateChild("PART_Presenter");

            presenter.Loaded += Presenter_Loaded;
        }
Esempio n. 19
0
 /// <summary>
 /// get a reference to the frame's content presenter
 /// this is the element we will fade in and out
 /// </summary>
 public override void OnApplyTemplate()
 {
     _contentPresenter = GetTemplateChild("PART_FrameCP") as ContentPresenter;
     base.OnApplyTemplate();
 }
Esempio n. 20
0
        /// <summary>
        /// when the items change we remove any generated panel children and add any new ones as necessary
        /// </summary>
        /// <param name="e"></param>
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);

            if (_itemsHolder == null)
            {
                return;
            }

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Reset:
                _itemsHolder.Children.Clear();

                if (base.Items.Count > 0)
                {
                    base.SelectedItem = base.Items[0];
                    UpdateSelectedItem();
                }

                break;

            case NotifyCollectionChangedAction.Add:
            case NotifyCollectionChangedAction.Remove:

                // Search for recently deleted items caused by a Drag/Drop operation
                if (e.NewItems != null && _deletedObject != null)
                {
                    foreach (var item in e.NewItems)
                    {
                        if (_deletedObject == item)
                        {
                            // If the new item is the same as the recently deleted one (i.e. a drag/drop event)
                            // then cancel the deletion and reuse the ContentPresenter so it doesn't have to be
                            // redrawn. We do need to link the presenter to the new item though (using the Tag)
                            ContentPresenter cp = FindChildContentPresenter(_deletedObject);
                            if (cp != null)
                            {
                                int index = _itemsHolder.Children.IndexOf(cp);

                                (_itemsHolder.Children[index] as ContentPresenter).Tag =
                                    (item is TabItem) ? item : (this.ItemContainerGenerator.ContainerFromItem(item));
                            }
                            _deletedObject = null;
                        }
                    }
                }

                if (e.OldItems != null)
                {
                    foreach (var item in e.OldItems)
                    {
                        _deletedObject = item;

                        // We want to run this at a slightly later priority in case this
                        // is a drag/drop operation so that we can reuse the template
                        this.Dispatcher.BeginInvoke(DispatcherPriority.DataBind,
                                                    new Action(delegate()
                        {
                            if (_deletedObject != null)
                            {
                                ContentPresenter cp = FindChildContentPresenter(_deletedObject);
                                if (cp != null)
                                {
                                    this._itemsHolder.Children.Remove(cp);
                                }
                            }
                        }
                                                               ));
                    }
                }

                UpdateSelectedItem();
                break;

            case NotifyCollectionChangedAction.Replace:
                throw new NotImplementedException("Replace not implemented yet");
            }
        }
Esempio n. 21
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            this.Navigated += TestFrame_Navigated;

            _rootViewbox = (Viewbox)GetTemplateChild("RootViewbox");
            _rootGrid    = (Grid)GetTemplateChild("RootGrid");

            // The root grid is in a Viewbox, which lays out its child with infinite
            // available size, so set the grid's dimensions to match the window's.
            // When running tests on phone, these dimensions will end up getting set to
            // match the screen's unscaled dimensions to deal with scale factor differences
            // between devices and provide some consistency.
            SetRootGridSizeFromWindowSize();

            Window.Current.SizeChanged += OnWindowSizeChanged;

            // NOTE: The "BackButton" element automatically has a handler hooked up to it by Frame
            // just by being named "BackButton"
            _backButton = (Button)GetTemplateChild("BackButton");

            _toggleThemeButton        = (Button)GetTemplateChild("ToggleThemeButton");
            _toggleThemeButton.Click += ToggleThemeButton_Click;

            _pagePresenter = (ContentPresenter)GetTemplateChild("PagePresenter");

            _innerFrameInLabDimensions        = (ToggleButton)GetTemplateChild("InnerFrameInLabDimensions");
            _innerFrameInLabDimensions.Click += _innerFrameInLabDimensions_Click;

            _goBackInvokerButton        = (Button)GetTemplateChild("GoBackInvokerButton");
            _goBackInvokerButton.Click += GoBackInvokerButton_Click;

            _closeAppInvokerButton        = (Button)GetTemplateChild("CloseAppInvokerButton");
            _closeAppInvokerButton.Click += CloseAppInvokerButton_Click;

            _waitForIdleInvokerButton        = (Button)GetTemplateChild("WaitForIdleInvokerButton");
            _waitForIdleInvokerButton.Click += WaitForIdleInvokerButton_Click;

            _idleStateEnteredCheckBox = (CheckBox)GetTemplateChild("IdleStateEnteredCheckBox");

            _errorReportingTextBox = (TextBox)GetTemplateChild("ErrorReportingTextBox");
            _logReportingTextBox   = (TextBox)GetTemplateChild("LogReportingTextBox");

            _currentPageTextBlock      = (TextBlock)GetTemplateChild("CurrentPageTextBlock");
            _currentPageTextBlock.Text = "Home";

            _viewScalingCheckBox            = (CheckBox)GetTemplateChild("ViewScalingCheckBox");
            _viewScalingCheckBox.Checked   += OnViewScalingCheckBoxChanged;
            _viewScalingCheckBox.Unchecked += OnViewScalingCheckBoxChanged;

            _waitForDebuggerInvokerButton        = (Button)GetTemplateChild("WaitForDebuggerInvokerButton");
            _waitForDebuggerInvokerButton.Click += WaitForDebuggerInvokerButton_Click;

            _debuggerAttachedCheckBox = (CheckBox)GetTemplateChild("DebuggerAttachedCheckBox");

            _goFullScreenInvokerButton        = (Button)GetTemplateChild("FullScreenInvokerButton");
            _goFullScreenInvokerButton.Click += GoFullScreenInvokeButton_Click;

            _unhandledExceptionReportingTextBox = (TextBox)GetTemplateChild("UnhandledExceptionReportingTextBox");
            _keyInputReceived = (CheckBox)GetTemplateChild("KeyInputReceived");
        }
        private static void CreateDragAdorner(DropInfo dropInfo)
        {
            var dragInfo         = dropInfo.DragInfo;
            var template         = GetDropAdornerTemplate(dropInfo.VisualTarget) ?? GetDragAdornerTemplate(dragInfo.VisualSource);
            var templateSelector = GetDropAdornerTemplateSelector(dropInfo.VisualTarget) ?? GetDragAdornerTemplateSelector(dragInfo.VisualSource);

            UIElement adornment = null;

            var useDefaultDragAdorner = template == null && templateSelector == null && GetUseDefaultDragAdorner(dragInfo.VisualSource);
            var useVisualSourceItemSizeForDragAdorner = GetUseVisualSourceItemSizeForDragAdorner(dragInfo.VisualSource);

            if (useDefaultDragAdorner)
            {
                template = dragInfo.VisualSourceItem.GetCaptureScreenDataTemplate(dragInfo.VisualSourceFlowDirection);
            }

            if (template != null || templateSelector != null)
            {
                if (dragInfo.Data is IEnumerable && !(dragInfo.Data is string))
                {
                    if (!useDefaultDragAdorner && ((IEnumerable)dragInfo.Data).Cast <object>().Count() <= 10)
                    {
                        var itemsControl = new ItemsControl();
                        itemsControl.ItemsSource          = (IEnumerable)dragInfo.Data;
                        itemsControl.ItemTemplate         = template;
                        itemsControl.ItemTemplateSelector = templateSelector;
                        itemsControl.Tag = dragInfo;

                        if (useVisualSourceItemSizeForDragAdorner)
                        {
                            var bounds = VisualTreeHelper.GetDescendantBounds(dragInfo.VisualSourceItem);
                            itemsControl.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
                        }

                        // The ItemsControl doesn't display unless we create a grid to contain it.
                        // Not quite sure why we need this...
                        var grid = new Grid();
                        grid.Children.Add(itemsControl);
                        adornment = grid;
                    }
                }
                else
                {
                    var contentPresenter = new ContentPresenter();
                    contentPresenter.Content                 = dragInfo.Data;
                    contentPresenter.ContentTemplate         = template;
                    contentPresenter.ContentTemplateSelector = templateSelector;
                    contentPresenter.Tag = dragInfo;

                    if (useVisualSourceItemSizeForDragAdorner)
                    {
                        var bounds = VisualTreeHelper.GetDescendantBounds(dragInfo.VisualSourceItem);
                        contentPresenter.SetValue(FrameworkElement.MinWidthProperty, bounds.Width);
                        contentPresenter.SetValue(FrameworkElement.MinHeightProperty, bounds.Height);
                    }

                    adornment = contentPresenter;
                }
            }

            if (adornment != null)
            {
                if (useDefaultDragAdorner)
                {
                    adornment.Opacity = GetDefaultDragAdornerOpacity(dragInfo.VisualSource);
                }

                var rootElement = RootElementFinder.FindRoot(dropInfo.VisualTarget ?? dragInfo.VisualSource);
                DragAdorner = new DragAdorner(rootElement, adornment, GetDragAdornerTranslation(dragInfo.VisualSource));
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Reads and restores the navigation history of a Frame from a provided serialization string.
        /// </summary>
        /// <param name="navigationState">
        /// The serialization string that supplies the restore point for navigation history.
        /// </param>
        /// <returns></returns>
        public async Task SetNavigationState(string navigationState)
        {
            try
            {
                Debug.Assert(navigationState[0] == '1');
                Debug.Assert(navigationState[1] == ',');
                int parseIndex = 2;
                var totalPages = ParseNumber(navigationState, ref parseIndex);

                this.BackStack.Clear();
                this.ForwardStack.Clear();
                this.CurrentJournalEntry = null;

                if (_currentPagePresenter != null)
                {
                    _pagePresentersPanel.Children.Remove(_currentPagePresenter);
                    _currentPagePresenter = null;
                }

                if (totalPages == 0)
                {
                    this.CurrentJournalEntry = null;
                    await UnloadAllPreloaded();

                    return;
                }

                var backStackDepth = ParseNumber(navigationState, ref parseIndex);

                var reversedForwardStack = new List <JournalEntry>(totalPages - backStackDepth);

                for (int i = 0; i < totalPages; i++)
                {
                    var je = ParseJournalEntry(navigationState, ref parseIndex);

                    Debug.WriteLine("Type: {0}, Param: {1}", je.SourcePageType, je.Parameter);
                    if (i < backStackDepth)
                    {
                        this.BackStack.Push(je);
                    }
                    else
                    {
                        reversedForwardStack.Add(je);
                    }
                }

                reversedForwardStack.Reverse();

                foreach (var journalEntry in reversedForwardStack)
                {
                    this.ForwardStack.Push(journalEntry);
                }

                var forwardJournalEntry = this.ForwardStack.Peek();

                await NavigateCore(
                    forwardJournalEntry.SourcePageType,
                    forwardJournalEntry.Parameter,
                    NavigationMode.Forward);
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Could not deserialize frame navigation state.", "navigationState", ex);
            }
        }
 /// <summary>
 /// Represents the ChartViewContentPresenter class
 /// </summary>
 public ChartViewContentPresenter(ContentPresenter contentpresenter)
 {
     this.ContentPresenter = contentpresenter;
 }
Esempio n. 25
0
 protected override void OnTransitionEnded(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
 {
     oldContent.BeginAnimation(UIElement.OpacityProperty, null);
 }
Esempio n. 26
0
        public void ItemsControlTemplatesTest()
        {
            string text = @"
            <ItemsControl xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <DockPanel/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.Template>
                    <ControlTemplate>
                        <Grid>
                            <TextBlock Text='Header'/>
                            <ItemsPresenter ItemContainerGenerator='{TemplateBinding ItemsControl.ItemContainerGenerator}' Template='{TemplateBinding ItemsControl.ItemsPanel}'/>
                        </Grid>
                    </ControlTemplate>
                </ItemsControl.Template>
                <ItemsControl.ItemContainerStyle>
                    <Style>
                        <Setter Property='DockPanel.Dock' Value='Bottom'/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text='{Binding}'/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>";

            ItemsControl itemsControl = XamlLoader.Load(XamlParser.Parse(text)) as ItemsControl;

            itemsControl.Items.Add("item1");
            itemsControl.Items.Add("item2");
            itemsControl.Items.Add("item3");

            Grid grid = itemsControl.VisualChildren.FirstOrDefault() as Grid;

            Assert.IsNotNull(grid);
            Assert.AreEqual(2, grid.Children.Count);

            TextBlock      textBlock      = grid.Children[0] as TextBlock;
            ItemsPresenter itemsPresenter = grid.Children[1] as ItemsPresenter;

            Assert.IsNotNull(textBlock);
            Assert.IsNotNull(itemsPresenter);
            Assert.AreEqual("Header", textBlock.Text);

            DockPanel dockPanel = itemsPresenter.VisualChildren.FirstOrDefault() as DockPanel;

            Assert.IsNotNull(dockPanel);
            Assert.AreEqual(3, dockPanel.Children.Count);

            ContentPresenter presenter1 = dockPanel.Children[0] as ContentPresenter;
            ContentPresenter presenter2 = dockPanel.Children[1] as ContentPresenter;
            ContentPresenter presenter3 = dockPanel.Children[2] as ContentPresenter;

            Assert.IsNotNull(presenter1);
            Assert.IsNotNull(presenter2);
            Assert.IsNotNull(presenter3);
            Assert.AreEqual(Dock.Bottom, DockPanel.GetDock(presenter1));
            Assert.AreEqual(Dock.Bottom, DockPanel.GetDock(presenter2));
            Assert.AreEqual(Dock.Bottom, DockPanel.GetDock(presenter3));

            TextBlock textBlock1 = presenter1.VisualChildren.FirstOrDefault() as TextBlock;

            Assert.IsNotNull(textBlock1);
            Assert.AreEqual("item1", textBlock1.Text);

            itemsControl.Items[0] = "item4";
            Assert.IsFalse(presenter1.VisualChildren.Any());
            Assert.IsNull(textBlock1.Text);

            ContentPresenter presenter4 = dockPanel.Children[0] as ContentPresenter;

            Assert.AreNotEqual(presenter1, presenter4);

            TextBlock textBlock4 = presenter4.VisualChildren.FirstOrDefault() as TextBlock;

            Assert.AreEqual("item4", textBlock4.Text);
        }
Esempio n. 27
0
        public virtual void CreateColumnHeaderContent(DataGrid grid, Border bdr, CellRange rng)
        {
            var c = grid.Columns[rng.Column];

            if (c.HeaderObject != null)
            {
                var tb = new ContentPresenter();
                tb.VerticalContentAlignment = VerticalAlignment.Center;
                tb.Content = c.HeaderObject;
                bdr.Child  = tb;
                // apply global foreground color
                if (grid.ColumnHeaderForeground != null)
                {
                    tb.Foreground = grid.ColumnHeaderForeground;
                }
                if (c.HeaderForeground != null)
                {
                    tb.Foreground = c.HeaderForeground;
                }
                tb.HorizontalAlignment = c.HeaderHorizontalAlignment;
                // show sort direction (after applying styles)
                if (grid.ShowSort && IsSortSymbolRow(grid, rng))
                {
                    // get the grid that owns the row (we could be printing this)
                    var g = grid.Columns.Count > 0 ? grid.Columns[0].Grid : grid;

                    // get sort direction and show it
                    ListSortDirection?sd = g.GetColumnSort(rng.Column);
                    if (sd.HasValue)
                    {
                        var icon = GetGlyphSort(sd.Value, tb.Foreground);
                        SetBorderContent(bdr, bdr.Child, icon, 1);
                    }
                }
            }
            else
            {
                // create TextBlock content
                var tb = new TextBlock();
                tb.VerticalAlignment = VerticalAlignment.Center;
                bdr.Child            = tb;

                // get unbound value
                var value = grid.ColumnHeaders[rng.Row, rng.Column];
                if (value != null)
                {
                    tb.Text = value.ToString();
                }

                // no unbound value? show column caption on first fixed row
                if (string.IsNullOrEmpty(tb.Text) && rng.Row == 0)
                {
                    tb.Text = grid.Columns[rng.Column].GetHeader() ?? "";
                }

                // apply global foreground color
                if (grid.ColumnHeaderForeground != null)
                {
                    tb.Foreground = grid.ColumnHeaderForeground;
                }

                // honor HeaderTemplate property

                if (c.HeaderTemplate != null)
                {
                    bdr.Padding = GetTemplatePadding(bdr.Padding); // Util.ThicknessEmpty;
                    bdr.Child   = GetTemplatedCell(grid, c.HeaderTemplate);
                    //bdr.Child = c.HeaderTemplate.LoadContent() as UIElement;
                }

                if (c.HeaderForeground != null)
                {
                    tb.Foreground = c.HeaderForeground;
                }
                tb.HorizontalAlignment = c.HeaderHorizontalAlignment;

                // show sort direction (after applying styles)
                if (grid.ShowSort && IsSortSymbolRow(grid, rng))
                {
                    // get the grid that owns the row (we could be printing this)
                    var g = grid.Columns.Count > 0 ? grid.Columns[0].Grid : grid;

                    // get sort direction and show it
                    ListSortDirection?sd = g.GetColumnSort(rng.Column);
                    if (sd.HasValue)
                    {
                        var icon = GetGlyphSort(sd.Value, tb.Foreground);
                        SetBorderContent(bdr, bdr.Child, icon, 1);
                    }
                }
            }
        }
Esempio n. 28
0
        private void RefreshSheetsContent()
        {
            BookPage bp0 = GetTemplateChild("sheet0") as BookPage;

            if (bp0 == null)
            {
                return;
            }

            BookPage bp1 = GetTemplateChild("sheet1") as BookPage;

            if (bp1 == null)
            {
                return;
            }

            ContentPresenter sheet0Page0Content = bp0.FindName("page0") as ContentPresenter;
            ContentPresenter sheet0Page1Content = bp0.FindName("page1") as ContentPresenter;
            ContentPresenter sheet0Page2Content = bp0.FindName("page2") as ContentPresenter;

            ContentPresenter sheet1Page0Content = bp1.FindName("page0") as ContentPresenter;
            ContentPresenter sheet1Page1Content = bp1.FindName("page1") as ContentPresenter;
            ContentPresenter sheet1Page2Content = bp1.FindName("page2") as ContentPresenter;

            Visibility bp0Visibility = Visibility.Visible;
            Visibility bp1Visibility = Visibility.Visible;

            bp1.IsTopRightCornerEnabled    = true;
            bp1.IsBottomRightCornerEnabled = true;

            Visibility sheet0Page0ContentVisibility = Visibility.Visible;
            Visibility sheet0Page1ContentVisibility = Visibility.Visible;
            Visibility sheet0Page2ContentVisibility = Visibility.Visible;
            Visibility sheet1Page0ContentVisibility = Visibility.Visible;
            Visibility sheet1Page1ContentVisibility = Visibility.Visible;
            Visibility sheet1Page2ContentVisibility = Visibility.Visible;

            DataTemplate dt = ItemTemplate;

            if (dt == null)
            {
                dt = defaultDataTemplate;
            }

            sheet0Page0Content.ContentTemplate = dt;
            sheet0Page1Content.ContentTemplate = dt;
            sheet0Page2Content.ContentTemplate = dt;
            sheet1Page0Content.ContentTemplate = dt;
            sheet1Page1Content.ContentTemplate = dt;
            sheet1Page2Content.ContentTemplate = dt;

            sheet0Page2ContentVisibility = _currentSheetIndex == 1 ? Visibility.Hidden : Visibility.Visible;
            int  count      = GetItemsCount();
            int  sheetCount = count / 2;
            bool isOdd      = (count % 2) == 1;

            if (_currentSheetIndex == sheetCount)
            {
                if (isOdd)
                {
                    bp1.IsTopRightCornerEnabled    = false;
                    bp1.IsBottomRightCornerEnabled = false;
                }
                else
                {
                    bp1Visibility = Visibility.Hidden;
                }
            }

            if (_currentSheetIndex == sheetCount - 1)
            {
                if (!isOdd)
                {
                    sheet1Page2ContentVisibility = Visibility.Hidden;
                }
            }

            if (_currentSheetIndex == 0)
            {
                sheet0Page0Content.Content = null;
                sheet0Page1Content.Content = null;
                sheet0Page2Content.Content = null;
                bp0.IsEnabled = false;
                bp0Visibility = Visibility.Hidden;
            }
            else
            {
                sheet0Page0Content.Content = GetPage(2 * (CurrentSheetIndex - 1) + 1);
                sheet0Page1Content.Content = GetPage(2 * (CurrentSheetIndex - 1));
                sheet0Page2Content.Content = GetPage(2 * (CurrentSheetIndex - 1) - 1);
                bp0.IsEnabled = true;
            }

            sheet1Page0Content.Content = GetPage(2 * CurrentSheetIndex);
            sheet1Page1Content.Content = GetPage(2 * CurrentSheetIndex + 1);
            sheet1Page2Content.Content = GetPage(2 * CurrentSheetIndex + 2);

            bp0.Visibility = bp0Visibility;
            bp1.Visibility = bp1Visibility;

            sheet0Page0Content.Visibility = sheet0Page0ContentVisibility;
            sheet0Page1Content.Visibility = sheet0Page1ContentVisibility;
            sheet0Page2Content.Visibility = sheet0Page2ContentVisibility;
            sheet1Page0Content.Visibility = sheet1Page0ContentVisibility;
            sheet1Page1Content.Visibility = sheet1Page1ContentVisibility;
            sheet1Page2Content.Visibility = sheet1Page2ContentVisibility;
        }
Esempio n. 29
0
		internal void UpdateFooter()
		{
			if (!loaded)
				return; 

			if (FooterTemplate == null)
			{
				if (footerPresenter != null)
				{
					if (Items.Contains(footerPresenter))
						Items.Remove(footerPresenter);
					footerPresenter = null;
				}
			}
			else
			{
				if (footerPresenter == null)
				{
					footerPresenter = new ContentPresenter();
					headerPresenter.Content = this.FindParentDataContext();
					footerPresenter.Visibility = ShowFooter ? Visibility.Visible : Visibility.Collapsed;
				}

				if (!Items.Contains(footerPresenter))
					Items.Add(footerPresenter);

				footerPresenter.ContentTemplate = FooterTemplate;
			}
		}
Esempio n. 30
0
        private void generateCrossword()
        {
            Crossword.Children.Clear();
            Crossword.RowDefinitions.Clear();
            Crossword.ColumnDefinitions.Clear();

            ContentPresenter cp = null;

            for (int row = 1; row <= vm.Puzzle.Rows; row++)
            {
                for (int col = 1; col <= vm.Puzzle.Cols; col++)
                {
                    cp = new ContentPresenter()
                    {
                        Content = new RegexPuzzleRectCellVM(vm, row, col)
                    };
                    cp.SetValue(Grid.RowProperty, row);
                    cp.SetValue(Grid.ColumnProperty, col);

                    Crossword.Children.Add(cp);
                }
            }

            Crossword.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });
            for (int row = 1; row <= vm.Puzzle.Rows; row++)
            {
                Crossword.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(40)
                });

                cp = new ContentPresenter()
                {
                    Content = new RegexPuzzleRectPatternVM(vm, row, 0)
                };
                cp.SetValue(Grid.RowProperty, row);
                cp.SetValue(Grid.ColumnProperty, 0);
                Crossword.Children.Add(cp);

                cp = new ContentPresenter()
                {
                    Content = new RegexPuzzleRectPatternVM(vm, row, vm.Puzzle.Cols + 1)
                };
                cp.SetValue(Grid.RowProperty, row);
                cp.SetValue(Grid.ColumnProperty, vm.Puzzle.Cols + 1);
                Crossword.Children.Add(cp);
            }
            Crossword.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });

            Crossword.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });
            for (int col = 1; col <= vm.Puzzle.Cols; col++)
            {
                Crossword.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(40)
                });

                cp = new ContentPresenter()
                {
                    Content = new RegexPuzzleRectPatternVM(vm, 0, col)
                };
                cp.SetValue(Grid.RowProperty, 0);
                cp.SetValue(Grid.ColumnProperty, col);
                Crossword.Children.Add(cp);

                cp = new ContentPresenter()
                {
                    Content = new RegexPuzzleRectPatternVM(vm, vm.Puzzle.Rows + 1, col)
                };
                cp.SetValue(Grid.RowProperty, vm.Puzzle.Rows + 1);
                cp.SetValue(Grid.ColumnProperty, col);
                Crossword.Children.Add(cp);
            }
            Crossword.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });
        }
Esempio n. 31
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();
            this.path = this.GetTemplateChild(PartPath) as Path;
            this.content = this.GetTemplateChild(PartContent) as ContentPresenter;
            this.contentContainer = this.GetTemplateChild(PartContentcontainer) as Grid;
            this.horizontalLine = this.GetTemplateChild(PartHorizontalline) as Line;
            this.verticalLine = this.GetTemplateChild(PartVerticalline) as Line;

            if (this.contentContainer == null)
            {
                throw new InvalidOperationException(string.Format("The TrackerControl template must contain a content container with name +'{0}'", PartContentcontainer));
            }

            if (this.path == null)
            {
                throw new InvalidOperationException(string.Format("The TrackerControl template must contain a Path with name +'{0}'", PartPath));
            }

            if (this.content == null)
            {
                throw new InvalidOperationException(string.Format("The TrackerControl template must contain a ContentPresenter with name +'{0}'", PartContent));
            }

            this.UpdatePositionAndBorder();
        }
Esempio n. 32
0
 public void Show(object content, Style gridStyle, Action callback = null)
 {
     ClosedCallback = callback;
     RunSafe(() =>
     {
         _child = new Grid
         {
             Width  = Window.Current.Bounds.Width,
             Height = Window.Current.Bounds.Height,
             Style  = gridStyle,
         };
         _presenter = new ContentPresenter
         {
             Width           = Window.Current.Bounds.Width,
             Height          = Window.Current.Bounds.Height,
             ContentTemplate = Template,
             Content         = content,
         };
         SetupPlacement(_presenter);
         if (TransitionCollection != null)
         {
             _presenter.ContentTransitions = TransitionCollection;
         }
         (_child as Grid).Children.Add(_presenter);
         var _focus = new TextBox
         {
             Name            = "Hidden_Focus_Grabbing_TextBox",
             RenderTransform = new ScaleTransform {
                 ScaleX = .01, ScaleY = .01
             },
             PreventKeyboardDisplayOnProgrammaticFocus = true,
             HorizontalAlignment    = HorizontalAlignment.Right,
             VerticalAlignment      = VerticalAlignment.Bottom,
             AllowFocusWhenDisabled = true,
             Opacity   = .001d,
             IsEnabled = false,
             IsTabStop = false,
             Height    = 1d,
             Width     = 1d,
         };
         (_child as Grid).Children.Add(_focus);
         var close = new Button
         {
             Content = new SymbolIcon {
                 Symbol = Symbol.Cancel
             },
             VerticalAlignment   = VerticalAlignment.Top,
             HorizontalAlignment = HorizontalAlignment.Right,
             Margin         = new Thickness(16),
             Padding        = new Thickness(16),
             Visibility     = CloseButtonVisibility,
             RequestedTheme = ElementTheme.Dark,
         };
         close.Click += (s, e) => Hide();
         (_child as Grid).Children.Add(close);
         _popup = new Windows.UI.Xaml.Controls.Primitives.Popup
         {
             Child = _child,
         };
         _popup.Opened += (s, e) =>
         {
             _focus.LosingFocus += (s1, e1) => e1.Handled = true;
             _focus.Focus(FocusState.Programmatic);
         };
         Window.Current.SizeChanged += Resize;
         _popup.IsOpen = IsShowing = true;
     });
 }
Esempio n. 33
0
 /// <summary>
 /// When the template is applied, get the template parts. Also, ensure that if the 
 /// content of the label changes, the label is re-positioned.
 /// </summary>
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     contentPart = this.GetTemplateChild("Content_PART") as ContentPresenter;
     canvasPart = this.GetTemplateChild("Canvas_PART") as Canvas;
     if (contentPart != null)
     {
         contentPart.SizeChanged += delegate(object sender, SizeChangedEventArgs e)
         {
             this.PositionLabel();
         };
     }
 }
Esempio n. 34
0
 private void ArrangeInitialElement(ContentPresenter element, double panelCenterX, double panelCenterY)
 {
     element.Arrange(new Rect(panelCenterX, panelCenterY, element.DesiredSize.Width, element.DesiredSize.Height));
 }
Esempio n. 35
0
        protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            Brush clone = CreateBrush(oldContent);

            Size           size     = transitionElement.RenderSize;
            MeshGeometry3D leftDoor = CreateMesh(new Point3D(),
                                                 new Vector3D(size.Width / 2, 0, 0),
                                                 new Vector3D(0, size.Height, 0),
                                                 1,
                                                 1,
                                                 new Rect(0, 0, 0.5, 1));

            GeometryModel3D leftDoorGeometry = new GeometryModel3D();

            leftDoorGeometry.Geometry = leftDoor;
            leftDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D leftRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);

            leftDoorGeometry.Transform = new RotateTransform3D(leftRotation);

            GeometryModel3D rightDoorGeometry = new GeometryModel3D();
            MeshGeometry3D  rightDoor         = CreateMesh(new Point3D(size.Width / 2, 0, 0),
                                                           new Vector3D(size.Width / 2, 0, 0),
                                                           new Vector3D(0, size.Height, 0),
                                                           1,
                                                           1,
                                                           new Rect(0.5, 0, 0.5, 1));

            rightDoorGeometry.Geometry = rightDoor;
            rightDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D rightRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);

            rightDoorGeometry.Transform = new RotateTransform3D(rightRotation, size.Width, 0, 0);

            Model3DGroup doors = new Model3DGroup();

            doors.Children.Add(leftDoorGeometry);
            doors.Children.Add(rightDoorGeometry);

            ModelVisual3D model = new ModelVisual3D();

            model.Content = doors;
            viewport.Children.Add(model);

            DoubleAnimation da = new DoubleAnimation(90 - 0.5 * FieldOfView, Duration);

            leftRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da = new DoubleAnimation(-(90 - 0.5 * FieldOfView), Duration);
            rightRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da            = new DoubleAnimation(0, Duration);
            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            clone.BeginAnimation(Brush.OpacityProperty, da);
        }
        /// <summary>
        /// Invoked whenever application code or internal processes (such as a rebuilding
        /// layout pass) call <see cref="OnApplyTemplate"/>. In simplest terms, this means the method
        /// is called just before a UI element displays in an application. Override this
        /// method to influence the default post-template logic of a class.
        /// </summary>
        protected override void OnApplyTemplate()
        {
            if (_scroller != null)
            {
                _scroller.Loaded -= Scroller_Loaded;
                _scroller.DirectManipulationCompleted -= Scroller_DirectManipulationCompleted;
                _scroller.DirectManipulationStarted   -= Scroller_DirectManipulationStarted;
            }

            if (_refreshIndicatorBorder != null)
            {
                _refreshIndicatorBorder.SizeChanged -= RefreshIndicatorBorder_SizeChanged;
            }

            if (_root != null)
            {
                _root.ManipulationStarted   -= Scroller_ManipulationStarted;
                _root.ManipulationCompleted -= Scroller_ManipulationCompleted;
            }

            _root                           = GetTemplateChild(PartRoot) as Border;
            _scroller                       = GetTemplateChild(PartScroller) as ScrollViewer;
            _scrollerContent                = GetTemplateChild(PartScrollerContent) as ItemsPresenter;
            _refreshIndicatorBorder         = GetTemplateChild(PartRefreshIndicatorBorder) as Border;
            _refreshIndicatorTransform      = GetTemplateChild(PartIndicatorTransform) as CompositeTransform;
            _defaultIndicatorContent        = GetTemplateChild(PartDefaultIndicatorContent) as TextBlock;
            _pullAndReleaseIndicatorContent = GetTemplateChild(PullAndReleaseIndicatorContent) as ContentPresenter;

            if (_root != null &&
                _scroller != null &&
                _scrollerContent != null &&
                _refreshIndicatorBorder != null &&
                _refreshIndicatorTransform != null &&
                (_defaultIndicatorContent != null || _pullAndReleaseIndicatorContent != null))
            {
                _scroller.Loaded += Scroller_Loaded;

                if (IsPullToRefreshWithMouseEnabled)
                {
                    _root.ManipulationMode       = ManipulationModes.TranslateY;
                    _root.ManipulationStarted   += Scroller_ManipulationStarted;
                    _root.ManipulationCompleted += Scroller_ManipulationCompleted;
                }

                _scroller.DirectManipulationCompleted += Scroller_DirectManipulationCompleted;
                _scroller.DirectManipulationStarted   += Scroller_DirectManipulationStarted;

                if (_defaultIndicatorContent != null)
                {
                    _defaultIndicatorContent.Visibility = RefreshIndicatorContent == null ? Visibility.Visible : Visibility.Collapsed;
                }

                if (_pullAndReleaseIndicatorContent != null)
                {
                    _pullAndReleaseIndicatorContent.Visibility = RefreshIndicatorContent == null ? Visibility.Visible : Visibility.Collapsed;
                }

                _refreshIndicatorBorder.SizeChanged += RefreshIndicatorBorder_SizeChanged;

                _overscrollMultiplier = OverscrollLimit * 8;
            }

            base.OnApplyTemplate();
        }