2017-08-15 11 views
0

その内容は表示されませんので、私はPopupFrameと呼ばれる以下のコントロールがあります。Xamarinフォーム - 私のContentPresenterが、私はまだXamarinフォームに慣れるよ

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 
    { 
     get { 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> 

<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> 

だから何が起こっていることはときContentView制御ショー、唯一のラベル(テキスト付き- TESTのTITLE - 表示されますが、ないListViewの)ということです。

また、ContentPreseterをContentViewに置き換えようとしましたが、同じ結果です。私のListViewは表示されません。そして、データが実際にListViewのItemsSource(コードビハインドで設定)に存在することを確認しました。

ContentViewの設定が間違っていますか?

答えて

1

TemplateBindingは、コントロールテンプレートの内側からバインドするためにのみ使用できます。バインディングが機能するには、ReferenceExtensionを使用して親コントロールを参照できます。

EXについて、あなたは次のように結合更新:

<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> 
+1

うわーは、×:リファレンスは間違いなく私に何か新しいものです。これはXFでRelativeSourceが欠落していた理由を説明します。 ありがとうございました、魅力的なように働きました! – Maximus

関連する問題