It was deeply funny for me. I could easily reproduce this. And then I could easily reproduce this without reference to Template 10. The violation code is this block in T10:
// title foreach (var resource in Application.Current.Resources .Where(x => x.Key.Equals(typeof(Controls.CustomTitleBar)))) { var control = new Controls.CustomTitleBar(); control.Style = resource.Value as Style; }
You can simplify this:
var a = Application.Current.Resources.ToArray();
Posted in OnLaunched
any application. Boom. The error itself occurs when we try to access a collection of resources, but only when the BasedOn
style is added to the resources.
After sitting with the platform team to try and justify pattern 10, everyone around the table began to scratch their heads. And when I understood @dachibox, you found a real bug on the XAML platform.
Here are just the current workaround until we update template 10.
<Page.Resources> <ResourceDictionary Source="..\Styles\Custom.xaml" /> </Page.Resources>
I mean, you are doing the work on the page, not the application. So, how do we fix template 10 without fixing the XAML platform? Take a look at this awkward code that we will use in Bootstrapper:
int count = Application.Current.Resources.Count; foreach (var resource in Application.Current.Resources) { var k = resource.Key; if (k == typeof(Controls.CustomTitleBar)) { var s = resource.Value as Style; var t = new Controls.CustomTitleBar(); t.Style = s; } count--; if (count == 0) break; }
An error, at least in the iterator counter property, which seems to increase rather than decrease when you iterate over it. Crazy huh? It turns out that this iterative path is not a common use case. But now it doesnโt matter, we raised the flag thanks to your question here.
I am updating Template 10 with a fix this week.
Good luck Jerry