stonstad
Topic Author
Posts: 104
Joined: 06 Jun 2016, 18:14

Initialized - How Not To Execute During XAML Build Step

20 Jun 2019, 00:41

When a XAML file changes externally I notice that OnInitialized is called in the code behind file. Most of the time this is fine, but occasionally I have dependencies on other state in this method which may not be initialized. Is there an easy way to have OnInitialized (from UserControl.Initialized) not execute during this XAML refresh/build step?

Tags:
 
User avatar
jsantos
Site Admin
Posts: 2588
Joined: 20 Jan 2012, 17:18
Contact:

Re: Initialized - How Not To Execute During XAML Build Step

20 Jun 2019, 11:31

Not calling OnInitialize when XAML is refreshing could give strange errors at parsing time or break thumbnails. What about having a way to inform your control that is is being reimported and that OnInitialize could be ignored?

We need to think more about it, it is definitely a issue.

PS: does it happen if you disable thumbnails in noesis settings?
 
stonstad
Topic Author
Posts: 104
Joined: 06 Jun 2016, 18:14

Re: Initialized - How Not To Execute During XAML Build Step

21 Jun 2019, 17:42

It's a minor nuisance, really. I just clear the errors from the Unity console and continue on. It just seems like there would be some way to know whether it is a runtime build or editor build. Another option might be using a different event such as Loaded(), but my understanding of that method is that it is reentrant, where as Initialized() is not.
 
User avatar
jsantos
Site Admin
Posts: 2588
Joined: 20 Jan 2012, 17:18
Contact:

Re: Initialized - How Not To Execute During XAML Build Step

24 Jun 2019, 14:53

Could you please open a ticket about it?
 
stonstad
Topic Author
Posts: 104
Joined: 06 Jun 2016, 18:14

Re: Initialized - How Not To Execute During XAML Build Step

30 Jun 2019, 04:01

I have an effective (and good enough) work-around: In UserControl.OnInitialized()...
        private void OnInitialized(object sender, NoesisEventArgs args)
        {
            if (!Application.isPlaying)
                return;
            
            // execute code here with external dependencies that are only initialized during game playback.    
              
        }

Who is online

Users browsing this forum: No registered users and 4 guests