c# - Can I reassign from code an object declared as a resource in XAML? -
I have a class for my data, 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 Then I get a reference for my code because I sometimes need this as well. It works well, but I can also load it another file from 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 MyData , and I call it my GUI I'm accessing data in binding by
MyData in the
window. Resource looks like
:
& lt; Local: Myadata X: Key = "MyData Instance" />
MyData myDataInstance; Public Manvindo () {Initialization (); MyDataInstance = (MyData) FindResource ("myDataInstance"); }
MyData by deserializing it from the file.
myDataInstance = (myData) serializer.Deserialize (fileStream);
myDataInstance
.
FindResource ()
?
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
Post a Comment