Page 1 of 1

Initialized - How Not To Execute During XAML Build Step

Posted: 20 Jun 2019, 00:41
by stonstad
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?

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

Posted: 20 Jun 2019, 11:31
by jsantos
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?

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

Posted: 21 Jun 2019, 17:42
by stonstad
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.

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

Posted: 24 Jun 2019, 14:53
by jsantos
Could you please open a ticket about it?

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

Posted: 30 Jun 2019, 04:01
by stonstad
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.    
              
        }