Example #1
0
 /// <summary>
 /// Invoked when this page is about to be displayed in a Frame.
 /// </summary>
 /// <param name="e">Event data that describes how this page was reached.  The Parameter
 /// property is typically used to configure the page.</param>
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     Thickness thick;
     thick.Top = 400;
     TextBlock txt = new TextBlock
     {
         Text = "Binding This Style in C#",
         VerticalAlignment = VerticalAlignment.Center,
         HorizontalAlignment = HorizontalAlignment.Center,
         Margin = thick,
         FontSize = 60,
         FontFamily = new FontFamily("Matura MT Script Capitals")
     };
     // Dynamically bind to an existed style.
     // 1. Setup the source.
     PropertyPath pPath = new PropertyPath("Foreground");
     Binding target = new Binding
     {
         ElementName = "topTxt",
         Path = pPath
     };
     // 2. Bind to the source. It is a DependencyObject, so you must use TextBlock.Foreground instead of Foreground.
     txt.SetBinding(TextBlock.ForegroundProperty, target);
     (this.Content as Grid).Children.Add(txt);
 }
Example #2
0
 private void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     MyConverterClass myConverter = new MyConverterClass();
     PropertyPath p = new PropertyPath("ActualWidth");
     Binding b = new Binding
     {
         ElementName = "page",
         Path = p,
         Converter = myConverter,
         ConverterParameter = "F7"
     };
     WTxt.SetBinding(TextBlock.TextProperty, b);
 }
Example #3
0
		public static Object Evaluate(Object container, PropertyPath propertyPath)
		{
			return Evaluate(container, new Binding { Source = container, Path = propertyPath });
		}
Example #4
0
 /// <summary>
 /// Constructor used by the XamlReader, for target late-binding
 /// </summary>
 internal TargetPropertyPath(string targetName, PropertyPath path)
 {
     TargetName = targetName;
     Path       = path;
 }
Example #5
0
 public TargetPropertyPath(object target, PropertyPath path)
 {
     Target = target;
     Path   = path;
 }
 private void AnimateEnemy(ContentControl enemy, double from, double to, PropertyPath propertyPath)
 {
     Storyboard storyboard = new Storyboard() { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever };
     DoubleAnimation animation = new DoubleAnimation()
     {
         From = from,
         To = to,
         Duration = new Duration(TimeSpan.FromSeconds(random.Next(4, 6)))
     };
     Storyboard.SetTarget(animation, enemy);
     Storyboard.SetTargetProperty(animation,propertyPath);
     storyboard.Children.Add(animation);
     storyboard.Begin();
 }
Example #7
0
 /// <summary>
 /// Helper for the UpdateDropIndicatorAnimationHeight method.
 /// </summary>
 private void UpdateDropIndicatorAnimationHeight(double height, Timeline animation)
 {
     DoubleAnimation da = animation as DoubleAnimation;
     if (da != null)
     {
         string targetName = Storyboard.GetTargetName(da);
         PropertyPath targetPath = new PropertyPath(Storyboard.GetTargetProperty(da));
         if ((targetName == ReorderListBoxItem.DropBeforeSpacePart ||
              targetName == ReorderListBoxItem.DropAfterSpacePart) &&
             targetPath != null && targetPath.Path == "Height")
         {
             if (da.From > 0 && da.From != height)
             {
                 da.From = height;
             }
             if (da.To > 0 && da.To != height)
             {
                 da.To = height;
             }
         }
     }
 }