Exemplo n.º 1
0
        public PageBuilder(double width, double height, int marginsLeft, int marginsTop, int marginsRight, int marginsBottom, ContentControl frame)
        {
            _page = new PageContent();
              _fixedPage = new FixedPage {Background = Brushes.White, Width = width, Height = height};

              _repeater = new Repeater();
              var repeatContainer = new Grid {Margin = new Thickness(marginsLeft, marginsTop, marginsRight, marginsBottom)};
              repeatContainer.Children.Add(_repeater);

              frame.SetValue(FixedPage.LeftProperty, 0.00);
              frame.SetValue(FixedPage.TopProperty, 0.00);
              frame.SetValue(FrameworkElement.WidthProperty, _fixedPage.Width);
              frame.SetValue(FrameworkElement.HeightProperty, _fixedPage.Height);

              _fixedPage.Children.Add(frame);
              ((IAddChild)_page).AddChild(_fixedPage);

              frame.Content = repeatContainer;

              frame.Measure(new Size(width, height));
              frame.Arrange(new Rect(0, 0, width, height));

              _repeater.Width = repeatContainer.ActualWidth;
              _repeater.Height = repeatContainer.ActualHeight;
        }
Exemplo n.º 2
0
		public void VisualTreeTest ()
		{
			ContentControl c = new ContentControl ();
			c.Content = new Rectangle ();

			Assert.VisualChildren (c, "#1"); // No visual children
			c.Measure (Size.Empty);
			Assert.VisualChildren (c, "#2",
				new VisualNode<Rectangle> ("#a", (VisualNode [ ]) null)
			);

			CreateAsyncTest (c, () => {
				Assert.VisualChildren (c, "#3",
					new VisualNode<ContentPresenter> ("#b",
						new VisualNode<Rectangle> ("#c")
					)
				);
			});
		}
Exemplo n.º 3
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")
			);
		}
Exemplo n.º 4
0
		public void VisualTreeTest5 ()
		{
			ContentPresenter presenter = null;
			ContentControl c = new ContentControl ();
			c.Content = "I'm a string";
			c.Measure (Size.Empty);

			CreateAsyncTest (c,
				() => {
					Assert.VisualChildren (c, "#1",
						new VisualNode<ContentPresenter> ("#a", p => presenter = p, null)
					);
					Assert.AreEqual (c.Content, presenter.DataContext, "#2");

					c.Content = new ConcreteFrameworkElement ();
				},
				() => {
					ContentPresenter old = presenter;
					Assert.VisualChildren (c, "#3",
						new VisualNode<ContentPresenter> ("#b", p => presenter = p, null)
					);
					Assert.AreSame (old, presenter, "#4");
					Assert.IsNull (presenter.DataContext, "#5");
				}
			);
		}
Exemplo n.º 5
0
        /// <summary>
        /// Renders the vector icon with the specified resource key, as an image of the specified size, and returns an URI for tile icons.
        /// </summary>
        /// <remarks>
        /// The key is for a ControlTemplate, it's the easiest way to store a path in resources.
        /// </remarks>
        private static Uri RenderVector( string templateKey, double size )
        {
            size = Math.Round( size );
            string fileName = string.Format( "Shared/ShellContent/{0}_{1}.png", templateKey, size );

            var control = new ContentControl();
            control.Template = (ControlTemplate) Application.Current.Resources[templateKey];
            control.Measure( new Size( size, size ) );
            control.Arrange( new Rect( 0, 0, size, size ) );

            var bitmap = new WriteableBitmap( (int) size, (int) size );
            bitmap.Render( control, null );
            bitmap.Invalidate();

            using ( var store = IsolatedStorageFile.GetUserStoreForApplication() )
            {
                if ( store.FileExists( fileName ) )
                {
                    store.DeleteFile( fileName );
                }

                using ( var stream = store.CreateFile( fileName ) )
                {
                    new PngWriter( stream, bitmap ).Write();
                }
            }

            return new Uri( "isostore:/" + fileName, UriKind.Absolute );
        }