Forum Xamarin.Forms

How to add resources to custom xaml ViewCell

Hi all.
As you know in xaml for each content page you can specify it's resource dictionary and use them like this

    <ContentPage xmlns="" xmlns:x="" x:Class="MyClass"
                 <local:InverseBoolConverter x:Key="inverse" />
                 <local:BoolToOpacityConverter x:Key="opacity" />
                 <local:InverseBoolToOpacityConverter x:Key="inverseOpacity" />
            <StackLayout Padding="0,20,0,5" IsVisible="{Binding IsNetworkAvailable, Converter={StaticResource inverse}}">

I'm also used to create ListView cell templates in separate xaml file to reuse them in different xaml pages. However I didn't find a way to use ResourceDictionary in my custom ViewCell xaml. I tried something like this

                 <local:BoolToOpacityConverter x:Key="opacity" />
                 <local:InverseBoolToOpacityConverter x:Key="inverseOpacity" />

However I get runtime exception that ViewCell doesn't have Resources property. Anyone knows how to achieve this? My pain purpose is being able to use converters in custom ViewCell xaml, and perhaps there is other way of doing that. Please don't comment that you can use custom property on BindingContext and place the converted data into that property instead of using converter, I know that. But I don't want to create custom property when the best practice in MVVM is creating converter. Any ideas?


  • TikiMoveTikiMove FRMember
    edited September 2015

    I'm also interested if someone has an answer :)

  • JoeSauve_xJoeSauve_x USXamarin Team Xamurai

    This is a neat trick! Nice work.

Sign In or Register to comment.