Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

LoadFromXaml and referencing containing page

$
0
0

I have a ListView that's on a ContentPage, and I want the ItemTemplate of the ListView to be user-definable - i.e. parsing the XAML for the template at runtime. However, I need to give the user the option of having a button that invokes a command on the page. See below XAML;

<SwipeView> <SwipeView.RightItems> <SwipeItems> <SwipeItem Text = ""Delete"" BackgroundColor=""Red"" Command=""{Binding Path=ItemDeletedCommand, Source={x:Reference multiEntryPage}}"" CommandParameter=""{Binding .}"" /> </SwipeItems> </SwipeView.RightItems> <SwipeView.Content> ... </SwipeView.Content> </SwipeView>

And my content page has the x:Name="multiEntryPage" attribute in its ContentPage element. The code I use to parse the XAML is shown here:

listView.ItemTemplate = new DataTemplate(() => new ViewCell().LoadFromXaml(xaml));

However, this gives the below error:

{Xamarin.Forms.Xaml.XamlParseException: Position 11:33. Can not find the object referenced by multiEntryPage at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.ProvideValue (System.Object& value, Xamarin.Forms.Xaml.ElementNode node, System.Object source, Xamarin.Forms.Xaml.XmlName propertyName)...

So I think it's fairly clear that the error is happening because the SwipeView XAML doesn't know about its parent at this stage, but I'm at a loss of how to resolve this. Any ideas?

Thanks!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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