I am just starting WPF and it is frustrating the hell out of me. It seems that many properties are null by default (at least those I am working on at the moment) and hence when it compiles and run, nothing happens.
Is there a quick way or a standard workflow procedure to set default values for WPF objects?
For example, I put a Canvas and a Button in XAML view, and then went to code view to add an event handler on the Button to Canvas.Children.Add(new Ellipse())
and then nothing happens. Then I thought maybe I should specify the Width and Height. Still nothing happens. Finally, after much struggling I found the Shape.Stroke
property.
Then there is no intuitive Ellipse.X
and Ellipse.Y
to position the Ellipse. Again, took an hour to find the Canvas.SetLeft()
.
The final straw is when I try to do Canvas.SetLeft(Random.Next(0, (int)Canvas.Width));
It give a runtime error because Canvas.Width
is NULL
?!!? Goodness...
Sure, WPF gives a lot of features, but seems like a lot of work coming from a Winforms Graphics.DrawEllipse()
.. *sweat*