ContentView for ListView

时间:2017-12-28 12:18:52

标签: xamarin xamarin.forms

我想为其中包含listview的布局创建自定义控件,这就是我想使用ContentView使用BindableProperties来绑定它的原因。但是,每当我在主视图中实现它时,我都会Microsoft.Unity.Practices调用我的ContentView的构造函数

ContentView.xaml

<StackLayout x:Name="Wrapper" Orientation="Vertical" WidthRequest="100" HeightRequest="100" IsVisible="False">
    <customControls:ListViewCustomRenderer x:Name="listCountries" VerticalOptions="FillAndExpand"
                                           ItemsSource="" ItemTapped="listCountries_ItemTapped"
                                           HorizontalOptions="FillAndExpand" HasUnevenRows="True"
                                           SeparatorColor="LightGray" SeparatorVisibility="Default">
        <customControls:ListViewCustomRenderer.ItemTemplate>
            <DataTemplate>
                  <ViewCell:CountryViewCell/>
            </DataTemplate>
        </customControls:ListViewCustomRenderer.ItemTemplate>
   </customControls:ListViewCustomRenderer>
   <Button x:Name="CancelButton"
                   Margin="0"
                   WidthRequest="70" 
                   HeightRequest="70"   
                   FontSize="36" 
                   TextColor="White"
                   BackgroundColor="Transparent" 
                   Text="" />
</StackLayout>

ContentView.xaml.cs

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListViewPopUp : ContentView
{
    public ListViewPopUp()
    {
        InitializeComponent();
    }
}

我认为这不是由于我的ViewCell,因为当我尝试删除它时,异常仍然会发生。有没有正确的方法在ListView内实现ContentView,就像我错过了什么?

0 个答案:

没有答案