1
votes

in my WPF project C# based, i have a window with a canvas, a treeview with some elements and a frame. The frame is used to contain a page, that changes based on treeview element selected. In page I have some textboxes in which I can write double values.

I.e. if I select first element of tree, the page loaded is Page1, in which there are 2 textboxes, if I select the second, the page loaded is Page2, in which there are 3 textboxes.

I need that, after changing value in textbox, I can do some operation on the canvas, i.e. if I write a value, a line into the canvas moves by that value in a certain direction. The event to manage is present in the Page class, but the Canvas is on Window class. So how can I manage canvas from outside the Window class? Or I need to change layout of Window and do not use a Frame to contain a page with textboxes? Any suggestion?

Thanks

1

1 Answers

1
votes

There are several options depending on your setup.

  1. You can bubble up the event from inside the Page class all the way to your Window.
  2. You could pass the Canvas object down into the Page class when it is created.
  3. If you're using MVVM or anything like that you could use the messaging framework available in most of the MVVM toolkits.
  4. I'm sure there are plenty of other options that people will chime in with.

Personally, I like 3 the best, but if you're not familiar with MVVM and the toolkits yet, that might be overkill for you.