c# - Can I reassign from code an object declared as a resource in XAML? -


I have a class for my data, MyData , and I call it my GUI I'm accessing data in binding by

I decided to set the main panel datacentext as an example of this object in my window so that I can tie my various controls with its members. So I can easily reference it in my XML, I have the MyData in the window. Resource looks like :

  & lt; Local: Myadata X: Key = "MyData Instance" />  

Then I get a reference for my code because I sometimes need this as well.

  MyData myDataInstance; Public Manvindo () {Initialization (); MyDataInstance = (MyData) FindResource ("myDataInstance"); }  

It works well, but I can also load it another file from MyData by deserializing it from the file. myDataInstance = (myData) serializer.Deserialize (fileStream);

I thought that I can simply reassign the code to code in my code, but this does not seem to be because my guinea does not reflect new figures . I think the restoring is breaking the link between the main panel's datacentext and myDataInstance .

  1. Is it possible to reassign the declared object in xaml?
  2. From XAM, is it possible to reach out to the declared members only in the code (only FindResource () ?
  3. If so, how?

you can try

  public class MainWindow {... zero UpdateResource () { MyDataInstance = (myData) serializer.Deserialize (fileStr) Eam); resource ["myDataInstance"] = myDataInstance;}}  

Then make sure that you reference your resource anytime instead of any StaticResource context Use the DynamicResource context. Adding objects to resource dictionaries and using dynamic resource references, as far as I know, XAML provides the only things available in the code The method is.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -