private void CreateContextContainer()
		{
			_container = new ContentControl();
			_container.Template = _skimmingPanel.ContextContainerTemplate;
			bool applied = _container.ApplyTemplate();
			_contextPanel = _container.Template.FindName("PART_ContextPanel", _container) as Panel;

			// For visual updates
			AddVisualChild(_container);
		}
Example #2
0
		public void VisualTreeTest3b ()
		{
			// Check whether the grid + TextBlock is reused or replaced
			Grid grid = null;
			TextBlock textBlock = null;
			ContentControl c = new ContentControl ();

			// If there is no control template, a Grid + TextBlock is
			// appended.
			c.Content = "I'm a string";
			Assert.IsTrue (c.ApplyTemplate (), "#1");
			Assert.VisualChildren (c, "#2",
				new VisualNode<Grid> ("#a", g => grid = g,
					new VisualNode<TextBlock> ("#b", b => textBlock = b)
				)
			);
			Assert.IsNull (textBlock.DataContext, "#3");
			Assert.AreEqual ("", textBlock.Text, "#4");

			// Changing the content to anther non-UIElement does not change
			// the grid/textblock instance
			c.Content = "Other string";
			Assert.IsFalse (c.ApplyTemplate (), "#5");
			Assert.VisualChildren (c, "#6",
				new VisualNode<Grid> ("#a", g => Assert.AreSame (g, grid, "#b"),
					new VisualNode<TextBlock> ("#c", b => Assert.AreSame (textBlock, b))
				)
			);
			Assert.AreEqual ("", textBlock.Text, "#7");
		}
Example #3
0
		public void VisualTreeTest3 ()
		{
			ContentControl c = new ContentControl ();

			c.Content = "I'm a string";

			Assert.VisualChildren (c, "#3"); // No visual children
			Assert.IsTrue (c.ApplyTemplate (), "#4");

			Assert.VisualChildren (c, "#5",
				new VisualNode<Grid> ("#a",
					new VisualNode<TextBlock> ("#b")
				)
			);

			TextBlock block = null;
			CreateAsyncTest (c,
				() => {
					Assert.VisualChildren (c, "#6",
						new VisualNode<ContentPresenter> ("#c",
							new VisualNode<Grid> ("#d",
								new VisualNode<TextBlock> ("#e", (b) => block = b)
							)
						)
					);
				},
				// This is probably a once off binding
				() => Assert.IsInstanceOfType<BindingExpressionBase> (block.ReadLocalValue (TextBlock.TextProperty), "#6")
			);
		}
Example #4
0
		public void VisualTreeTest2 ()
		{
			ContentControl c = new ContentControl ();
			Assert.VisualChildren (c, "#1");
			Assert.IsFalse (c.ApplyTemplate (), "#2");

			c.Content = new Rectangle ();

			Assert.VisualChildren (c, "#3"); // No visual children
			Assert.IsTrue (c.ApplyTemplate (), "#4");

			Assert.VisualChildren (c, "#5",
				new VisualNode<Rectangle> ("#a", (VisualNode [ ]) null)
			);

			CreateAsyncTest (c, () => {
				Assert.VisualChildren (c, "#6",
					new VisualNode<ContentPresenter> ("#b",
						new VisualNode<Rectangle> ("#c")
					)
				);
			});
		}
Example #5
0
		public void NewTemplateDoesNotApplyInstantly ()
		{
			ContentControl c = new ContentControl ();
			c.Content = "Test";
			CreateAsyncTest (c,
				() => c.ApplyTemplate (),
				() => {
					// Start off with the default template
					Assert.VisualChildren (c, "#1",
						new VisualNode<ContentPresenter> ("#a", (VisualNode []) null)
					);

					// Changing the template does not make it apply instantly.
					// It just clears the children.
					c.Template = CreateTemplate ("<Canvas />");
					Assert.VisualChildren (c, "#2");
				}, () => {
					Assert.VisualChildren (c, "#3",
						new VisualNode<Canvas> ("#c")
					);
				}
			);
		}
Example #6
0
		public void InvalidTemplateObjectChild ()
		{
			// ContentTemplate is ignored if there is a Template
			ContentControl c = new ContentControl {
				Content = "Test",
				Template = CreateTemplate ("<Storyboard />"),
			};
			CreateAsyncTest (c,
				() => c.ApplyTemplate (),
				() => {
					// Start off with the default template
					Assert.VisualChildren (c, "#1",
						new VisualNode<Grid> ("#a",
							new VisualNode<TextBlock> ("#b")
						)
					);
				}
			);
		}
Example #7
0
		public void IsEnabledTest3 ()
		{
			ContentControl a = new ContentControl ();
			ContentControl b = new ContentControl ();

			a.Content = b;
			a.IsEnabled = false;
			Assert.IsTrue (b.IsEnabled, "#1");

			a.ApplyTemplate ();
			Assert.IsTrue (b.IsEnabled, "#2");

			a.Measure (new Size { Height = 10,  Width = 10 });
			Assert.IsTrue (b.IsEnabled, "#3");

			CreateAsyncTest (a,
				() => Assert.IsFalse (b.IsEnabled, "#4")
			);
		}
Example #8
0
		public void DontCreateDynamicTransitionsOnAnimatedProperties ()
		{
			var c = new ContentControl { Template = GetTemplate_MultipleTransitions () };
			TestPanel.Children.Add (c);
			c.ApplyTemplate ();
			Assert.IsTrue (VisualStateManager.GoToState (c, "A", true), "#1");
			Assert.IsTrue (VisualStateManager.GoToState (c, "B", true), "#2");
		}
Example #9
0
		public void ContentTemplateNotUsed3 ()
		{
			ContentControl c = new ContentControl {
				Content = new Button { Content = "Hello World" },
				ContentTemplate = CreateDataTemplate ("<ContentControl />"),
				Template = null
			};
			CreateAsyncTest (c,
				() => c.ApplyTemplate (),
				() => {
					// Start off with the default template
					Assert.VisualChildren (c, "#1",
						new VisualNode<Button> ("#a", (VisualNode []) null)
					);
				}
			);
		}
Example #10
0
		public void ContentTemplateNotUsed2 ()
		{
			ContentControl c = new ContentControl {
				Content = "Test",
				ContentTemplate = CreateDataTemplate ("<ContentControl />"),
				Template = null
			};
			CreateAsyncTest (c,
				() => c.ApplyTemplate (),
				() => {
					// Start off with the default template
					Assert.VisualChildren (c, "#1",
						new VisualNode<Grid> ("#a",
							new VisualNode <TextBlock> ("#b")
						)
					);
				}
			);
		}
Example #11
0
		public void ContentTemplateNotUsed ()
		{
			ContentControl c = new ContentControl ();
			c.Content = "Test";
			c.ContentTemplate = CreateDataTemplate ("<ContentControl />");
			CreateAsyncTest (c,
				() => c.ApplyTemplate (),
				() => {
					// Start off with the default template
					Assert.VisualChildren (c, "#1",
						new VisualNode<ContentPresenter> ("#a", (VisualNode []) null)
					);
				}
			);
		}
Example #12
0
		public void ContentIsRoot ()
		{
			var c = new ContentControl { Content = new Rectangle () };

			Assert.IsTrue (c.ApplyTemplate (), "#1");
			Assert.AreEqual (1, VisualTreeHelper.GetChildrenCount (c), "#2");
			Assert.AreSame (c.Content, VisualTreeHelper.GetChild (c, 0), "#3");
		}
Example #13
0
		public void TransitionPropertyMismatchesStateProperty ()
		{
			var c = new ContentControl { Template = GetTemplate_MismatchedTargetProperties () };
			TestPanel.Children.Add (c);
			c.ApplyTemplate ();
			Assert.IsTrue (VisualStateManager.GoToState (c, "A", true), "#1");
			Assert.IsTrue (VisualStateManager.GoToState (c, "B", true), "#2");
			Assert.IsTrue (VisualStateManager.GoToState (c, "A", true), "#3");
		}
        protected virtual void OnContentChanged(object oldContent, object newContent)
        {
            if (this.grid == null)
            {
                this.ApplyTemplate();
            }

            ContentControl oldWrapper = this.currentWrappedContent;

            if (oldWrapper != null)
            {
                VisualStateGroup layoutStatesGroup = FindNameInWrapper(oldWrapper, "LayoutStates") as VisualStateGroup;

                if (layoutStatesGroup == null)
                {
                    this.grid.Children.Remove(oldWrapper);
                    SetContent(oldWrapper, null);
                }
                else
                {
                    layoutStatesGroup.CurrentStateChanged += delegate(object sender, VisualStateChangedEventArgs args)
                    {
                        this.grid.Children.Remove(oldWrapper);
                        SetContent(oldWrapper, null);
                    };
                    VisualStateManager.GoToState(oldWrapper, this.Reversed ? "BeforeLoaded" : "BeforeUnloaded", true);
                }
            }

            ContentControl newWrapper = new ContentControl();
            newWrapper.Style = this.TransitionStyle;
            newWrapper.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            newWrapper.VerticalContentAlignment = VerticalAlignment.Stretch;

            this.grid.Children.Add(newWrapper);
            newWrapper.ApplyTemplate();
            if (this.TransitionStyle != null)
            {
                SetContent(newWrapper, newContent);
                if (oldWrapper != null)
                {
                    VisualStateManager.GoToState(newWrapper, this.Reversed ? "BeforeUnloaded" : "BeforeLoaded", false);
                    VisualStateManager.GoToState(newWrapper, "AfterLoaded", true);
                }
            }

            this.currentWrappedContent = newWrapper;
        }
Example #15
0
		public void DataTemplateTest2 ()
		{
			// Fails in Silverlight 3
			ContentControl c = new ContentControl ();
			c.Content = new ConcreteFrameworkElement ();
			c.ContentTemplate = new DataTemplate ();
			CreateAsyncTest (c, 
				() => c.ApplyTemplate (),
				() =>
				    Assert.VisualChildren (c, "#1",
					    new VisualNode<ContentPresenter> ("#1a")
				    )
			);
		}
        private void CreateNote(NoteView note)
        {
            ContentControl noteControl = new ContentControl();
            noteControl.Name = "Note" + newNoteCount++;
            noteControl.Tag = note;
            Style template = this.TryFindResource("DesignerItemStyle") as Style;
            noteControl.Style = template;
            noteControl.ApplyTemplate();
            SolidColorBrush brush = new SolidColorBrush();
            brush.Color = ColorHelpers.GetColorByName(note.Color);
            noteControl.Background = brush;
            noteControl.Width = note.Width;
            noteControl.Height = note.Height;
            Canvas.SetTop(noteControl, note.Y);
            Canvas.SetLeft(noteControl, note.X);
            Transform rotate = new RotateTransform(note.RotateAngle, note.RotateCenterX, note.RotateCenterY);
            noteControl.RenderTransform = rotate;

            Button btnClose = noteControl.Template.FindName("btnClose", noteControl) as Button;
            Button btnChangeColor = noteControl.Template.FindName("btnChangeColor", noteControl) as Button;
            RichTextBox rtbBody = noteControl.Template.FindName("rtbNoteBody", noteControl) as RichTextBox;

            rtbBody.LoadFromRTF(note.Body);
            //SetValueToRichTextBox(note, rtbBody);

            MoveThumb moveThumb = noteControl.Template.FindName("moveThumb", noteControl) as MoveThumb;
            moveThumb.ApplyTemplate();
            TextBlock txtTitle = moveThumb.Template.FindName("txtTitle", moveThumb) as TextBlock;

            txtTitle.Text = note.User == null ? "新建" : note.User.Realname + note.AddTime.ToShortDateString();
            btnClose.Click += new RoutedEventHandler(btnClose_Click);
            btnChangeColor.Click += new RoutedEventHandler(btnChangeColor_Click);

            rtbBody.TextChanged += new TextChangedEventHandler(rtbBody_TextChanged);

            this.NoteCanvas.Children.Add(noteControl);
        }
Example #17
0
 private ContentControl GenerateTile(int i, int j)
 {
     ContentControl c = new ContentControl();
     c.Name = string.Format("tile{0}{1}", i.ToString(), j.ToString());
     c.Template = (ControlTemplate)FindResource("TileControl");
     c.ApplyTemplate();
     GridCanvas.Children.Add(c);
     Canvas.SetTop(c, TileSize * i + GridTop);
     Canvas.SetLeft(c, TileSize * j + GridLeft);
     return c;
 }