/* * Move all buttons into the wrap panel * */ void OnWrapPanel(object sender, RoutedEventArgs e) { ClearPanels(); for (int i = 0; i < numItems; i++) { LayoutToLayoutTarget target = Targets[i] as LayoutToLayoutTarget; (Hosts[i] as LayoutToLayoutHost).BeginAnimating(false); LTLWrapPanel.Children.Add(target); } }
/* * Link up the Host to the Target and initialize but do not start the timer * */ public void BindToTarget(LayoutToLayoutTarget t) { Target = t; t.Host = this; translation = new TranslateTransform(0, 0); RenderTransform = translation; Refresher = new DispatcherTimer(); Refresher.Interval = TimeSpan.FromMilliseconds(timeSpan); Refresher.Tick += OnAnimStateInvalidated; UpdateFromTarget(); }
/* * Move all buttons into the 3x3 grid * */ void OnGrid3(object sender, RoutedEventArgs e) { ClearPanels(); gridSize = 3; counter = 0; for (int i = 0; i < numItems; i++) { LayoutToLayoutTarget target = Targets[i] as LayoutToLayoutTarget; (Hosts[i] as LayoutToLayoutHost).BeginAnimating(false); Grid.SetRow(target, i / 3); Grid.SetColumn(target, i % 3); LTLGrid2.Children.Add(target); } }
void OnLoad(object sender, RoutedEventArgs e) { Application app = System.Windows.Application.Current; Panels.Add(LTLGrid); Panels.Add(LTLGrid2); Panels.Add(LTLStackPanel); Panels.Add(LTLWrapPanel); Debug.WriteLine("Grid children: " + ButtonGrid.Children.Count); for (int i = 0; i < numItems; i++) { LayoutToLayoutTarget target = new LayoutToLayoutTarget(); Targets.Add(target); target.Margin = new Thickness(5); target.MinWidth = 80; target.MinHeight = 50; target.BorderThickness = new Thickness(0); Grid.SetRow(target, i / 5); Grid.SetColumn(target, i % 5); LTLGrid.Children.Add(target); LayoutToLayoutHost host = new LayoutToLayoutHost(); Hosts.Add(host); host.BorderThickness = new Thickness(0); Button demoButton = new Button(); demoButton.Content = "# " + i; demoButton.Style = app.Resources["ButtonStyle"] as Style; demoButton.Click += OnAdvanceClick; host.Child = demoButton; //host.Child = Buttons[i] as Button; Canvas.SetLeft(host, 0); Canvas.SetTop(host, 0); LTLCanvas.Children.Add(host); host.BindToTarget(target); } }
/* * Break the cyclical reference * */ public void ReleaseFromTarget() { Target.Host = null; Target = null; }
/* * If the host gets unloaded, break the cyclical reference to make sure the GC does its job * */ void OnUnload(object sender, RoutedEventArgs e) { Target.Host = null; Target = null; }