Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XamlReader Wall
Message
De
09/03/2009 22:03:29
 
 
À
09/03/2009 15:14:17
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01386282
Message ID:
01386820
Vues:
29
>Hi,
>
>>I use the xaml writer/reader, but I'm using it with resources, so there is no codebehind to worry about?
>>This looked like a fragment of a save and open program. Is that correct? If not what are you trying to do here?
>
>The aim is to encapsulate (either in XML or in a single binary stream ) a Canvas object containing various content (including other nested canvases with, in turn, their own content). AFAICS the XAMLWriter/Reader is meant to reproduce a visual representation but not capsulate the actual hierarchy of objects. If, for example, you have a Usercontrol containing a couple of TextBlocks and add this to a Canvas the XAMLWriter will output something like:
><Canvas>
>  <UserControl>
>     <TextBlock/>
>    <TextBlock/>
>  </UserControl>
></Canvas>
>
>If this is passed to the XAMLReader then when it hits the UserControl element the constructor for the control is called resulting in the two TextBlocks being instantiated. The XAMLReader then moves on to the TextBlock element in the XML fragment and creates that as well - thus duplicating the version already created within the UserControl itself. If the TextBlock in question doesn't have a name then it will do this quite happily (if it IS named then you get the Exception previously mentioned) - but you still have two instances in existence. Any code behind references the instance within the UserControl. The one you see is the second one.
>
>I guess I'm just trying to do something that this was never meant for :-{
>It's beginning to look as if there is no 'high-level' way of doing this....
>Best,
>Viv

I think you are right on that. My understanding is that the XAML reader/writer was primarily designed to handle loose XAML like the resource dictionaries that I use it with. You might be able to still use the writer, but you would need to create a custom reader for it. In the project I mentioned, I actually just read the resource.xaml as an xml doc I then only use the reader/writer to instantiate specific objects that I need to work with or display. (I only feed it part of the tree.) it wasn't too hard to code.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform