DataTemplateSelector and Triggers

KerfuffleKerfuffle USUniversity ✭✭

I apologize if this is a repeat question. I did try searching for DataTemplateSelector and viewed several of the topics, but I was unable to find this question.

I have a question about Forms that is similar to the WPF question found on SO. For my DataTemplateSelector I read through Nish Anil's example on GitHub

I am having issues converting from WPF XAML to Forms XAML. The question is this: Is there some resource I can read that will help me understand how to convert this example into Forms xaml or does anyone have an example out there of using data triggers to re-apply a DataTemplateSelector?

Snippet:

<ContentPage.BindingContext>
    <viewModels:AgeGroupPageViewModel x:Name="m_ViewModel"/>
</ContentPage.BindingContext>
<ContentPage.Resources>
    <ResourceDictionary>
      <selector:AgeGroupSelector x:Key="AgeGroupSelector"/>
    </ResourceDictionary>
</ContentPage.Resources>    

...

<ListView HorizontalOptions="Start"
                CachingStrategy="RecycleElement"
                SeparatorVisibility="None"
                IsPullToRefreshEnabled="False"
                ItemsSource="{Binding AgeGroups, Mode=OneWay}"
                ItemTemplate="{StaticResource AgeGroupSelector}"
                BackgroundColor="White"
                MinimumWidthRequest="200">
        ...
</ListView>

I am trying to trigger off of two bool properties on any given AgeGroup object: IsNew and IsInEditMode. I've tried using style templates (and received an error about an invalid resource key), doing a direct copy & modify, and a few other things that would just worsen the signal to noise ratio in this question. Any help in understanding if and how the linked example translates into Forms would be very much appreciated.

Answers

  • KerfuffleKerfuffle USUniversity ✭✭
    edited September 2016

    Well. I gave up on triggers. I've read that they don't exist in Forms yet, so I'm skipping the idea. Instead, I've had to go with the much less efficient and user-friendly option: reloading the entire listview when I want a new view to show up in any given spot. It's ugly, it flickers, and it's annoying, but it works in this case because my list is so small. If anyone ever reads this and has a better idea, I'd be happy to read it.

Sign In or Register to comment.