Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Please clarify whether the Canvas control can hold a Xaml page content (can we load Xaml into Canvas dynamically by reading the Xaml page?)

Thanks.
Posted
Comments
Sergey Alexandrovich Kryukov 13-May-13 10:36am    
Good question, a 5. When I was answering your previous questions I wasn't sure. But why doing so?
—SA
Mohammed Hameed 14-May-13 1:00am    
Thank you Sergey for +5 :).
I'm developing a utility in WPF/C#. This will be used by developers & client to create simple Xaml pages on the fly with basic form to perform CRUD operations and may be a grid as well for displaying Records. It will have a Toolbox and a Properties Box (like in VS :)), so for first time created the page will have only the root grid. Now if user wants they can add controls thru Toolbox and can set properties also. Finally, this page will be converted to Silverlight so that it will be embedded to the hosted Xap package in web server.

Hope it was clear. If any queries plz let me know.
Sergey Alexandrovich Kryukov 14-May-13 1:47am    
OK, thanks for your clarification...
—SA

1 solution

Whilst I have never tried to directly host a page in the canvas control, I can confirm that you can host it in a Frame control sitting on the canvas control. Then set the source of the Frame control to show the Page control. Please see below:
XML
<canvas>
    <frame x:name="m_ChildPageView" xmlns:x="#unknown">
        Source="ChildPageView.xaml" 
        Canvas.Left="150" Canvas.Top="150"
        Width="2800" Height="1500"/>
</frame></canvas>


This solution would allow you to show your content, without having to read the XAML page yourself.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-May-13 10:36am    
5ed.
—SA
Mohammed Hameed 14-May-13 1:06am    
Hi,
Thanks for your answer. But the page will be loaded at Rutime and also once it is loaded drag/drop feature will be enabled from parent page to this page. So that new controls can be added to this page. Will it support these features if Frame is used?? Please clarify..
Mohammed Hameed 14-May-13 1:07am    
You can check my first comment, for better understanding, posted to explain Sergey about the tool.
Walby 14-May-13 4:26am    
No you won't be able to drag and drop controls onto the frame, straight out of the box.

But you could implement this yourself. Here's a good tutorial on implementing drag and drop functionality: http://wpftutorial.net/DragAndDrop.html. Then you need to check what control the user is dragging, then insert it onto the page programmatically and decide where the control should be placed in the visual tree.

Once you have made the required changes, you will have to re-load the frame's source though.

Alternatively you could look at a XAML designer framework to achieve this.
Mohammed Hameed 14-May-13 5:58am    
Thanks for your inputs.
Now I'm almost close to correct approach. +4 for your efforts :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900