0

I add DataTemplateSelector in FlowListView(Basically same as ListView).

<ContentView
    ...
    BindingContext="{Binding PatientImageListVM, Source={StaticResource VMLocator}}">
    ...
    <flv:FlowListView
        ...
        HasUnevenRows="true">
        <flv:FlowListView.FlowColumnTemplate>
            <local:PatientImageListDataTemplateSelector/>
        </flv:FlowListView.FlowColumnTemplate>
    </flv:FlowListView>
</ContentView>

And I use this code for get cell with binding.

button.SetBinding(Button.CommandParameterProperty, ".");

But I want to use some variables in ViewModel binded with ContentView in DataTemplateSelector. I tried this code but not working.

label.SetBinding(Label.IsVisibleProperty, 
    "{Binding BindingContext.LabelVisibility, Source={x:Reference Page}}");

How can I get a vatiable in ViewModel in DataTemplateSellector?

Stephane Delcroix
  • 16,134
  • 5
  • 57
  • 85
kingsj0405
  • 149
  • 14

1 Answers1

0
label.SetBinding(Label.IsVisibleProperty, new Binding("BindingContext.LabelVisibility", source: this));

This should works. You should pass the "Page" to your binding with "this". So you should set your binding when you create the ItemTemplate

lv.ItemTemplate = new DataTemplate(() =>
{
    //....
    label.SetBinding(Label.IsVisibleProperty, new Binding("BindingContext.LabelVisibility", source: this));
}
Alessandro Caliaro
  • 5,623
  • 7
  • 27
  • 52
  • Thank you for your anwser. I found solution `"{Binding ImageListVM.LabelVisibility, Source={StaticResource VMLocator}}"`. When I replace with your code, it works, too. – kingsj0405 Mar 07 '17 at 00:58