Search code examples
xamarin.formsitemtemplate

Xamarin 2.3.3.193 and ItemTemplate


I've updated Xamarin Forms in my Xamarin project. Now this code doesn't work any more.

var view = (View)ItemTemplate.CreateContent();
if (view != null) {
    var bindableObject = view as BindableObject;
    if (bindableObject != null)
        bindableObject.BindingContext = newItem;
    _imageStack.Children.Add(view);
}

The problem is (View)ItemTemplate.CreateContent() goes in error:

Message: Can't resolve name on Element

Source: Xamarin.Forms.Xaml

Stack: at Xamarin.Forms.Xaml.ReferenceExtension.ProvideValue (System.IServiceProvider serviceProvider) [0x000b6] in [...]

In the Debug window I can see the following info

02-20 17:44:04.450 I/art     (13331): Starting a blocking GC Explicit
02-20 17:44:04.482 I/art     (13331): Explicit concurrent mark sweep GC freed 436(24KB) AllocSpace objects, 0(0B) LOS objects, 21% free, 14MB/18MB, paused 762us total 31.310ms
02-20 17:44:04.482 I/System  (13331): FinalizerDaemon: finalize objects = 48
02-20 17:44:04.484 D/Mono    (13331): GC_TAR_BRIDGE bridges 20 objects 20 opaque 0 colors 20 colors-bridged 20 colors-visible 20 xref 0 cache-hit 0 cache-semihit 0 cache-miss 0 setup 0.11ms tarjan 0.06ms scc-setup 0.08ms gather-xref 0.00ms xref-setup 0.00ms cleanup 0.30ms
02-20 17:44:04.484 D/Mono    (13331): GC_BRIDGE: Complete, was running for 34.10ms
02-20 17:44:04.484 D/Mono    (13331): GC_MINOR: (Nursery full) time 4.22ms, stw 4.53ms promoted 32K major size: 3504K in use: 2748K los size: 6404K in use: 5406K

My function save an image in memory from the camera in ImageSource format, byte[] and the length in byte of this image.


Solution

  • This indicates that the XAML you are loading contains a {x:Reference foo} markup extension and, at runtime, no element defined with a x:Name="foo" was found in the hierarchy.

    Without seeing your XAML, it's impossible to figure if the issue is in your code, or if it's a bug in Xamarin.Forms.