Пример #1
0
 private void AnimationValuePropertyChanged()
 {
     if (null == LayoutTransformer)
     {
         // No LayoutTransformer set; try to find it by LayoutTransformerName
         LayoutTransformer = FindName(LayoutTransformerName) as LayoutTransformer;
         if (null == LayoutTransformer)
         {
             throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                               "AnimationMediator was unable to find a LayoutTransformer named \"{0}\".",
                                                               LayoutTransformerName));
         }
     }
     // The Transform hasn't been updated yet; schedule an update to run after it has
     Dispatcher.BeginInvoke(() => LayoutTransformer.ApplyLayoutTransform());
 }
        public void SetNullTransform()
        {
            List <ContentControl> controlsToTest = new List <ContentControl>(ControlsToTest);

            foreach (ContentControl control in controlsToTest)
            {
                LayoutTransformer layoutTransformer = control as LayoutTransformer;
                if (null != layoutTransformer)
                {
                    layoutTransformer.LayoutTransform = new RotateTransform {
                        Angle = 10
                    };
                    layoutTransformer.LayoutTransform = null;
                }
            }
        }
Пример #3
0
        private void NapisTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key == Windows.System.VirtualKey.Enter)
            {
                string   textToStack  = NapisTextBox.Text;
                string[] wordsToStack = textToStack.Split(new char[] { ' ' });

                int maxHeight = (int)Math.Ceiling(MainGrid.ActualWidth);
                int maxWidth  = (int)Math.Ceiling(MainGrid.ActualHeight);

                int fontSize = 120;

                WordsDistribution distribution = CreateProperWordsDistribution(fontSize, wordsToStack, maxWidth, maxHeight);
                TextStack.Children.Clear();
                distribution.Rows.Reverse();
                foreach (string row in distribution.Rows)
                {
                    TextBlock t = new TextBlock();
                    t.FontSize = distribution.FontSize;
                    t.Text     = row;
                    //t.FontWeight = FontWeights.Bold;
                    t.TextAlignment = TextAlignment.Center;

                    LayoutTransformer lt = new LayoutTransformer();
                    lt.HorizontalAlignment = HorizontalAlignment.Stretch;
                    lt.VerticalAlignment   = VerticalAlignment.Stretch;


                    lt.Content = t;
                    RotateTransform rt = new RotateTransform();
                    rt.Angle           = 90;
                    lt.LayoutTransform = rt;
                    TextStack.Children.Add(lt);
                }


                TextStack.Visibility           = Visibility.Visible;
                NapisInputContainer.Visibility = Visibility.Collapsed;
            }
        }
        /// <summary>
        /// Tests the specified LayoutTransformer scenario.
        /// </summary>
        /// <param name="scenario">Scenario to test.</param>
        /// <param name="controlsToTest">Stream of controls to test.</param>
        private void TestScenario(LayoutTransformerScenario scenario, IEnumerable <ContentControl> controlsToTest)
        {
            LayoutTestPanel panel = new LayoutTestPanel(scenario.MeasureSize, scenario.ArrangeSize);

            foreach (ContentControl control in controlsToTest)
            {
                LayoutTransformer layoutTransformer = control as LayoutTransformer;
                if (null != layoutTransformer)
                {
                    layoutTransformer.LayoutTransform = scenario.Transform;
                }
#if !SILVERLIGHT
                else
                {
                    control.LayoutTransform = scenario.Transform;
                }
#endif
                control.Content = scenario.Child;
                panel.Children.Add(control);
            }
            TestAsync(
                panel,
                () =>
            {
                foreach (ContentControl control in controlsToTest)
                {
                    FrameworkElement child = control.Content as FrameworkElement;
#if !SILVERLIGHT
                    control.Measure(scenario.MeasureSize);
#endif
                    AssertAreEqual(scenario.DesiredSize, child.DesiredSize, control, "Measure");
#if !SILVERLIGHT
                    control.Arrange(new Rect(new Point(), scenario.ArrangeSize));
#endif
                    AssertAreEqual(scenario.RenderSize, child.RenderSize, control, "Arrange");
                }
            });
        }
        public void NonUIElementContentInContentTemplate()
        {
            DataTemplate contentTemplate = (DataTemplate)XamlReader.
#if SILVERLIGHT
                                           Load(
#else
                                           Parse(
#endif
                @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>" +
                @"<Grid Width='150' Height='150'>" +
                @"<ContentControl Content='{TemplateBinding Content}'/>" +
                @"</Grid>" +
                @"</DataTemplate>");
            Size                  containerSize  = new Size(150, 150);
            Size                  contentSize    = new Size(106, 106);
            LayoutTestPanel       panel          = new LayoutTestPanel(containerSize, containerSize);
            List <ContentControl> controlsToTest = new List <ContentControl>(ControlsToTest);

            foreach (ContentControl control in controlsToTest)
            {
                control.Content     = 1.0;
                Transform transform = new RotateTransform {
                    Angle = 45
                };
                LayoutTransformer layoutTransformer = control as LayoutTransformer;
                if (null != layoutTransformer)
                {
                    layoutTransformer.LayoutTransform = transform;
                }
#if !SILVERLIGHT
                else
                {
                    control.LayoutTransform = transform;
                }
#endif
                control.ContentTemplate = contentTemplate;
                panel.Children.Add(control);
            }
            TestAsync(
                panel,
                () =>
            {
                foreach (ContentControl control in controlsToTest)
                {
                    control.ApplyTemplate();
                    ContentPresenter contentPresenter;
                    DependencyObject child = VisualTreeHelper.GetChild(control, 0);
                    contentPresenter       = child as ContentPresenter;
                    if (null == contentPresenter)
                    {
                        contentPresenter = VisualTreeHelper.GetChild(child, 0) as ContentPresenter;
                    }
                    Assert.IsNotNull(contentPresenter);
#if !SILVERLIGHT
                    control.Measure(containerSize);
#endif
                    AssertAreEqual(contentSize, contentPresenter.DesiredSize, control, "Measure");
#if !SILVERLIGHT
                    control.Arrange(new Rect(new Point(), containerSize));
#endif
                    AssertAreEqual(contentSize, contentPresenter.RenderSize, control, "Arrange");
                }
            });
        }