Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Unable to get parent in ListView HeaderTemplate

$
0
0

Hello,

I have a ListView and a Header with HeaderTemplate.

The HeaderTemplate is in an extra .xaml file, so that I can reuse it.

          <ListView.HeaderTemplate>
                        <DataTemplate>
                            <my:HeaderControl />
                        </DataTemplate>
           </ListView.HeaderTemplate>

public class MyViewModel {

public Command SomeCommand;
public MyObject MyObject;
}

The Header is bound to MyObject, but needs also to call the SomeCommand command.

So I wrote a MarkupExtension which allows me to get the ParentPage.

{Binding Path=Vm.SomeCommand, Source={myex:ParentPage}}

  public static Page  ParentPage(this Element element)
  {
            while (element != null && !(element is Page))
                element = element.Parent;
            return element as Page;
  }

Now the problem:

If u use an external (reusable) xaml file in a ListView's DataTemplate there is no parent set for the external control.

Any ideas on this?


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>