![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | C#: Canvas.Loaded not firing I have a Canvas that acts as a background image, let's call this bgCanvas. I also have another Canvas that contains a TextBlock, let's call this fgCanvas. bgCanvas always exists in the scene. An event is raised and as a result, I create a fgCanvas and add it to bgCanvas's children collection. Before I add it though, I wire-up fgCanvas.Loaded because I need to check it's ActualHeight property and you can't do that before it's calculated. So the idea is, create this canvas, wire up it's Loaded event, then add it and wait for the event to fire, then retrieve ActualHeight. Problem is Loaded never fires. I can visually see fgCanvas on the screen so Load must have occurred right? But the handler is never invoked. I tried LayoutUpdated but that fires way too often and it's a plain EventHandler with sender always null. I wish there was a SizeCalculated event or something.. any ideas? |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: C#: Canvas.Loaded not firing I worked around this by simplifying and such. I have the bgCanvas and I subclassed TextBlock which will lay on top. In the subclass I override OnRenderSizeChanged() and raise a custom event. This gets me the ActualHeight as soon as it's calculated. I didn't plan on having to create a custom eventhandler delegate and event args but unfortunately OnRenderSizeChanged() uses SizeChangedInfo yet RenderSizeEventHandler uses RenderSizeEventArgs and the two are not interchangeable. Not only that but when I tried to instantiate a RenderSizeEventArg I got an error saying there is no constructor defined.. WHAT? So in the end I had to roll my own TextBlock subclass, eventargs, and eventhandler. But it works and that's all that matters right? I'd still like to know why that Canvas was being rendered on the screen but Loaded was never firing.... |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: C#: Canvas.Loaded not firing I'm not 100% sure what you're doing (so I may not be answering your question), but in a quick test with a Canvas called bgCanvas already on the form: public partial class Window1 { private Canvas fgCanvas; public Window1() { this.InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { fgCanvas = new Canvas(); fgCanvas.Loaded += new RoutedEventHandler(fgCanvas_Loaded); fgCanvas.Width = 100; fgCanvas.LayoutUpdated += new EventHandler(fgCanvas_LayoutUpdated); bgCanvas.Children.Add(fgCanvas); } void fgCanvas_LayoutUpdated(object sender, EventArgs e) { txtSize.Text = fgCanvas.RenderSize.ToString(); } void fgCanvas_Loaded(object sender, RoutedEventArgs e) { Console.WriteLine("Loaded"); } } Both the Loaded and LayoutUpdated events are raised as expected. The sender arg is null though in the LayoutUpdated event -- so I needed to store a reference to the fgCanvas object as a private member variable. The txtSize TextBox I added gets the value of "100,0" when I click a button on the window. What I'm mostly confused about is that it seems like you're trying to get a size for the Canvas after layout? The Canvas normally doesn't size -- it's content can extend beyond it's boundaries without clipping, so it's size is normally irrelevant. I don't see any RenderSizeEventHanlder in the 3.0 documentation anywhere .... ? http://www.wiredprairie.us/journal "znelson" <znelson@gmail.com> wrote in message news:1173838305.954092.84480@n76g2000hsh.googlegroups.com... >I worked around this by simplifying and such. I have the bgCanvas and > I subclassed TextBlock which will lay on top. In the subclass I > override OnRenderSizeChanged() and raise a custom event. This gets me > the ActualHeight as soon as it's calculated. > > I didn't plan on having to create a custom eventhandler delegate and > event args but unfortunately OnRenderSizeChanged() uses > SizeChangedInfo yet RenderSizeEventHandler uses RenderSizeEventArgs > and the two are not interchangeable. Not only that but when I tried to > instantiate a RenderSizeEventArg I got an error saying there is no > constructor defined.. WHAT? > > So in the end I had to roll my own TextBlock subclass, eventargs, and > eventhandler. But it works and that's all that matters right? > > I'd still like to know why that Canvas was being rendered on the > screen but Loaded was never firing.... > |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DataGridView firing way to many SelectionChangedEvents! Please Help | Simon Harvey | .NET General | 5 | 08-11-2008 10:43 AM |
| Linkbutton firing every other time issue | mazdotnet | .NET General | 0 | 03-30-2008 06:50 PM |
| Help sound firing out external and headset. Annoying my vanpool. | Magoo | Vista General | 0 | 09-29-2007 02:39 PM |
| Triggers Firing for Child Objects | gregbacchus@nospam.nospam | Avalon | 0 | 05-14-2007 03:59 PM |
| firing noise in wmp11 | Neerav Kothari | Vista General | 2 | 04-03-2007 03:32 PM |