tags:

views:

27

answers:

1

Hi friends, I am new to wpf.I want to apply animations for r1,r2,r3,r4,e1,e2. I have to access these object names in my .xaml file for writing storyboards so that i can apply animations.How can i acces these object names in .xaml file? Can you send me sample applicationsfor how to create dynamic objects and how to access it into .xaml for applying animations

This is a part of my .cs file

namespace WpfApplication1 { /// /// Interaction logic for Window1.xaml /// public partial class Window1 : Window { Rectangle r1, r2, r3, r4; Ellipse e1, e2;
Shape contact,lvi; int flag=0; Point startPoint,cp; private Point enterPoint,p; public Window1() { InitializeComponent(); } . . . . . private void Canvas_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("MyFormat")) { contact = e.Data.GetData("MyFormat") as Shape; Canvas CanvasView = sender as Canvas; //MessageBox.Show(contact.GetType().ToString()); string savedObject = XamlWriter.Save(contact); StringReader stringReader = new StringReader(savedObject); XmlReader xmlReader = XmlReader.Create(stringReader); lvi = (Shape)XamlReader.Load(xmlReader);

            if (contact is Rectangle && contact.Name == "rect1" && r1 == null)
            {
                r1 = (Rectangle)lvi;
                r1.Margin = new Thickness(151, 129, 0, 0);
                CanvasView.Children.Add(r1);


            }
            else
            if (contact is Rectangle && contact.Name == "rect2" && r2 == null)
            {
                r2 = (Rectangle)lvi;
                r2.Margin = new Thickness(122, 142, 0, 0);
                canvas1.Children.Add(r2);
            }
            else
            if (contact is Rectangle && contact.Name == "rect3" && r3 == null)
            {
                r3 = (Rectangle)lvi;
                r3.Margin=new Thickness(132,225,0,0);
                canvas1.Children.Add(r3);
            }
            else 
            if (contact is Rectangle && contact.Name == "rect4" && r4==null )
            {
                r4 = (Rectangle)lvi;
                r4.Margin = new Thickness(177, 225,0,0);
                canvas1.Children.Add(r4);
            }
            else 
            if (contact is Ellipse && contact.Name == "ellipse1" && e1==null)
            {
                 e1 = (Ellipse)lvi;
                e1.Margin=new Thickness(123,74,0,0);
                canvas1.Children.Add(e1);
               // e1.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(ellipse_MouseLeftButtonDown);
            }
            else 
            if (contact is Ellipse && contact.Name == "ellipse2" && e2 == null)
            {
                e2 = (Ellipse)lvi;
                e2.Margin = new Thickness(324, 214, 0, 0);
                canvas1.Children.Add(e2);
            }
            else
            {
                MessageBox.Show("can not drop this item");
            }
        }
        }
}

}

A: 

In xaml you can only bind to public properties, or use a value converter.

jeffo