XamlWriter / Reader & # 8594; calls to multiple constructors leading to duplication of elements

I'm stuck here. I use the dragndrop library that serializes draggable UIElements through XamlWriter.Save ().

Now I am trying to reproduce some instances of a class extending the Grid. in the constructor, I insert some elements into the visual tree. the constructor is called when the object is deserialized and the elements are added again (and again and again depending on how often I draw). Unfortunately, Children.Count tells me that there are no children if I get the value from the constructor. if I get it from the outside (by myGrid.Children.Count), it gives me a higher (unwanted) amount.

is there any other function i should use to initialize visual effects? or in any other way to prevent duplication?

thanks and greetings

+3
source share
1 answer

It took some time, but I seem to have found a solution.
Now I can create a base class that already contains visual elements that need all subclasses. and they can be analyzed using XamlWriter / Reader without duplicates. hmm.

1) UserControl ( Add- > UserControl, Add- > Class )
2) InitializeControl();
3) InitializeControl() , ,
4) xamlwrite/xamlread/

, - ...

- : . , . , XamlReader UIElements, InitializeComponent(), , xaml-parsed. , :/

.

- , : if(HasContent)
Initialize();
else
Reinitialize();
Multiinitialize();

Initialize() UIElements , Reinitialize() ( control = FindName("controlName")), Multiinitialze() XamlReader.

, UserControl xaml, . , -, NullPointerExceptions. , .

. , !

+1

Source: https://habr.com/ru/post/1753217/


All Articles