locked
Generic subclassing from XAML RRS feed

  • Question

  • User101007 posted

    I am using generic subclassing in XAML with x:TypeArguments. So far it is working great !

    The only problem I have is that when I use a ValueConverter from a StaticResource declared in the Resources, then I get a XAML parser exception when it tries to load the "Type". I know the ValueConverter is fine and it gets added to the Resource dictionary.

    I get an exception of type 'Xamarin.Forms.Xaml.XamlParseException' occurred in Xamarin.Forms.Xaml.DLL The Message is: Type vw:PageBase not found in xmlns clr-namespace:App.Mobile.Views;assembly=App.Mobile This happens at the following location in the Stack Trace: at Xamarin.Forms.Xaml.XamlParser.GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo) at Xamarin.Forms.Xaml.StaticResourceExtension.LookupNamedResource(INode node, String key)

    I think it is not considering the x:TypeArguments when it is trying to find the base generic type.

    <vw:PageBase.Resources>
        <ResourceDictionary>
          <cnv:StatusToTextConverter x:Key="cnvStatus" />
        </ResourceDictionary>
      </vw:PageBase.Resources>
    
     <Label Text="{Binding Status_Id, Converter={StaticResource cnvStatus}}"></Label>
    

    Any solution? Can I maybe hook onto or override the Xamarin.Forms.Xaml.StaticResourceExtension to consider the Type ?

    Tuesday, February 3, 2015 1:43 PM

All replies

  • User101007 posted

    I tried to create a new IMarkupExtension based on the StaticResourceExtension but that proved to be too much work and unfortunately the Xamarin.Forms.Xaml.StaticResourceExtension is sealed...

    So for the interim I am using the following workaround: I'm just using a Static Extension

    <Label Text="{Binding status_id, Converter={x:Static cnv:StatusToTextConverter.StatusToTextConverterInstance}}" />

    Wednesday, February 4, 2015 8:25 AM
  • User49629 posted

    It appears that StaticResource was broken in a recent release of Xamarin Forms. I am using the same workaround as you until it is fixed. I believe the following bug report will cover it, although it may need to be supplemented to clarify that there is a general issue with the use of StaticResource: https://bugzilla.xamarin.com/show_bug.cgi?id=26680

    Friday, February 6, 2015 12:32 AM
  • User49629 posted

    @StephanusvanStaden I was able to get StaticResource working again on my end with some tweaks. Can you share your entire XAML file and perhaps the .cs code-behind as well?

    Friday, February 6, 2015 2:44 AM