I've been playing around with WPF lately, and its nice to use XAML. But XAML is helpful only when the layout is not yet done. It is, after all a markup language. What i want to achieve is loading an image when the window loads, creating a white border around that image, and showing the two on the main window.
I followed the tree structure that XAML uses, but somehow everytime i debug, nothing is visible on the form... why is this happening?
C# |
As you can see i create a Grid, then an image, then a border and basically recreate the tree as it would have been done in XML image ==child of ==> border == child of ==> grid
But when i run this, i get a blank window. I don't want to forcibly put controls on my window. Later on I'd like to make my own custom image class which would essentially contain a border and an image. Any clues about why i'm not able to see it?
I'm obviously doing something wrong.
Thanks,
Mittal


Sam HobbsRank #108 · 20.5K reputationPosted Oct 21, 2010, 8:04 PM EDT
asim mittal3 reputationPosted Oct 21, 2010, 11:53 PM EDT
Instead of adding the grid in the constructor as shown above, i added it on the Form's UI using XAML. Then on form_load i created the image and the border and added them to the grid. Having said that, it seems rather weird why the previous approach didn't work.
What if I wanted to add controls to a window on the fly (at runtime), and I didn't have a grid or a stackpanel on the window. I had even written a little more code to explicitly set the visibility properties of all the elements (from the code above) to Visible, but that didn't work either.
But is this regular behavior??