Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XAML WPF Silverlight C#4.0 , +
Hi,
 
Can anybody help me to suggest how to Load Xaml file in a Container (eg: Canvas or please suggest any other suitable container) in a xaml page in WPF.
 
Solution along with code is highly appreciated.
 

 
Thanks in advance.
Posted 11-May-13 1:21am
Edited 11-May-13 2:23am
v2
Comments
Mohammed Hameed at 11-May-13 6:22am
   
Any quick solutions highly appreciated.
Sergey Alexandrovich Kryukov at 11-May-13 23:22pm
   
Id depends on what's in that XAML file. I never had problem with putting the appropriate XAML content in a canvas. What did you try and what's the problem?
—SA
Mohammed Hameed at 13-May-13 1:25am
   
Thanks for your comment. The XAML contains the default xaml page content in WPF. I have to load this in a canvas but provided I should be able to implement drag/drop feature in future. So, can a Canvas supports drag/drop? Also, can u plz send a sample of loading xaml in canvas?
Thanks.
Sergey Alexandrovich Kryukov at 13-May-13 1:30am
   
I don't think a page can be a child of Canvas. You need to use XAML vector graphics object, which can be another Canvas.
—SA
Mohammed Hameed at 13-May-13 1:38am
   
Thanks. Can you plz send a sample.
Sergey Alexandrovich Kryukov at 13-May-13 1:43am
   
Would need too much time. You could better try to do it by yourself and ask a question if you face any problems.
To get a sample of XAML good for such things, use open-source Inkscape (wonderful application, a must to have, especially for a developer), draw something and export drawing as XAML (perhaps, manually removed unwanted Name attributes).
—SA
Mohammed Hameed at 13-May-13 1:48am
   
Okay, sure, I will. Thanks Sergey for your help. Can u post the same suggestions as Solution so that I can accept it?
Sergey Alexandrovich Kryukov at 13-May-13 2:08am
   
Done. I haven't done if for quite a while now, but, if you face some problems, I'll try to help when I find a bit of extra time. As I remember, it was quite easy to do. I also remember I send a test assignment to a job seeker (not the most advanced one) with XAML drawing, and this guy reused my own picture by inserting in into his code resource and then working with available object. I was pleased with it, because this is was the most productive form of laziness. Is I remember, he did it for the first time, so it tells me that it is easy enough for people.
—SA
Mohammed Hameed at 13-May-13 1:50am
   
I have one more query plz, recently I have posted a Tip/Trick article but it is showing status as closed now. Reviewers (admins) have given a feedback as quality is poor. How can I get the detailed feedback information so that I will consider those things for my future posts as this was my first article.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm not sure you can make a page a child of Canvas, but it surely could be another Canvas instance. You can read a Canvas object from the XAML file and insert the result of it.
 
For a sample of appropriate XAML, you can use use open-source Inkscape (wonderful application, a must to have, especially for a developer), draw something and export drawing as XAML:
http://en.wikipedia.org/wiki/Inkscape[^],
http://www.inkscape.org/[^].
 
Perhaps you need to manually remove unwanted Name attributes. As far as I remember, I had to do some manual cleanup of the Inkscape export, but it can easily be automated.
 
—SA
  Permalink  
v2
Comments
Mohammed Hameed at 13-May-13 2:26am
   
Thanks a lot for the answer...
Sergey Alexandrovich Kryukov at 13-May-13 2:29am
   
My pleasure.
—SA
Mohammed Hameed at 13-May-13 2:34am
   
I have one more query plz, recently I have posted a Tip/Trick article but it is showing status as closed now. Reviewers (admins) have given a feedback as quality is poor. How can I get the detailed feedback information so that I will consider those things for my future posts as this was my first article..
Sergey Alexandrovich Kryukov at 13-May-13 2:36am
   
You have to write to admins...
—SA
Mohammed Hameed at 13-May-13 2:41am
   
From where I can write to admins, plz provide the menu options.
Sergey Alexandrovich Kryukov at 13-May-13 2:55am
   
When you publish the article, one of the admins sends you e-mail notification. If not, please ask here:
http://www.codeproject.com/Forums/1645/Site-Bugs-Suggestions.aspx
(I understand this won't be a bug or suggestion, but this forum is checked by admins on a regular basis, unlike others...)
—SA
Mohammed Hameed at 13-May-13 3:06am
   
Thanks..
Sergey Alexandrovich Kryukov at 13-May-13 3:54am
   
Sure. Good luck with your article.
—SA
Mohammed Hameed at 13-May-13 10:02am
   
Thanks a lot.
Mohammed Hameed at 16-May-13 5:30am
   
Hi Sergey.
By now I have experimented practically with drag/drop. First I have tried to use Canvas to load the Xaml page but it is throwing the exception: Page can have only Window or Frame as parent. Next I used one Frame and in this Frame successfully able to load the page but unable to drop any element. I mean Drop event is not firing once inside the boundary of Frame control (eventhough there is a AllowDrop property set to true). Then I wrapped the Frame under a Canvas control but still I am only able to drag/drop to canvas area other than Frame.
Finally, it is like both are having distinct issue, canvas cannot be parent to a page and frame does not support drag/drop feature.
Can you please give your valuable suggestions on this and recommend any other suitable approach.
Thanks in advance.
Sergey Alexandrovich Kryukov at 16-May-13 9:52am
   
I never tried drag-n-drop with Canvas, don't feel those problems, sorry...
—SA

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

  Print Answers RSS
0 OriginalGriff 215
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 159
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 13 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100