xaml - Xamarin Forms - My ContentPresenter won't show its Content -
i'm still getting used xamarin forms, have following control called popupframe:
popupframe.cs
[xamlcompilation(xamlcompilationoptions.compile)] public partial class popupframe : contentview { public static readonly bindableproperty popupcontentproperty = bindableproperty.create(nameof(popupcontent), typeof(view), typeof(popupframe)); public view popupcontent { { return (view)getvalue(popupcontentproperty); } set { setvalue(popupcontentproperty, value); } } public popupframe() { initializecomponent(); } } popupframe.xaml
<?xml version="1.0" encoding="utf-8"?> <contentview xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:class="testapp.core.controls.popupframe"> <frame> <stacklayout> <label text="--- test title ---" /> <contentpresenter content="{templatebinding popupcontent}" /> </stacklayout> </frame> </contentview> in view:
<popctl:popupframe horizontaloptions="center" verticaloptions="center"> <popctl:popupframe.popupcontent> <listview x:name="listusers"> <listview.itemtemplate> <datatemplate> <viewcell> <viewcell.view> <label text="{binding name}" horizontaloptions="centerandexpand" verticaloptions="center" /> </viewcell.view> </viewcell> </datatemplate> </listview.itemtemplate> </listview> </popctl:popupframe.popupcontent> </popctl:popupframe> so what's happening when contentview control shows, label (with text -- test title -- displayed, not listview).
i've tried replacing contentpreseter contentview, same result: listview doesn't not show. , made sure data in fact exist in itemssource of listview (set in code-behind).
is contentview setup wrong??
templatebinding can used bind inside control-template. in order binding work - can use referenceextension refer parent control.
for ex, update binding following:
<contentview xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:class="testapp.core.controls.popupframe" x:name="_parent"> <frame> <stacklayout> <label text="--- test title ---" /> <contentpresenter content="{binding path=popupcontent, source={x:reference _parent}}" /> </stacklayout> </frame> </contentview>
Comments
Post a Comment