Xamarin xaml绑定列表

时间:2017-06-26 02:54:21

标签: c# xaml xamarin

我目前正在进行XamarinAlliance挑战,但我偶然发现了3号。我设法让后端应用程序启动并运行并将sql express连接到数据库并插入一些数据。到目前为止一切都还不错。

但现在我似乎无法将数据存入应用程序的列表中。它总是说计数为0并且没有显示任何内容。不对。我通过VS连接数据库到服务器并进行查询,数据就在那里。

所以,这是我的主页:

public partial class MainPage : ContentPage
{
    public static string mobileServiceClientUrl = "http://onepiecealliance.azurewebsites.net/";
    public static MobileServiceClient Client = new MobileServiceClient(mobileServiceClientUrl);
    public static IMobileServiceTable<Character> CharacterTable = Client.GetTable<Character>();
    private static List<Character> characterList { get; set; }

    public MainPage()
    {
        InitializeComponent();
        characterList = new List<Character>();
        GetCharactersAsync();
        BindingContext = new CharacterModelList();
    }

    async public void list_ItemTapped(object sender, ItemTappedEventArgs e)
    {
        Character item = (Character)e.Item;
        await Navigation.PushAsync(new Characters(item.Name, item.Description));
        ((ListView)sender).SelectedItem = null;

    }

    public async void GetCharactersAsync()
    {
        characterList = await CharacterTable.ToListAsync();
    }

    //Model
    public class Character
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }


    //Controller
    public class CharacterModelList : BindableObject
    {
        public List<Character> CharacterList1
        {
            get { return characterList; }
            set { characterList = value; }
        }

        public CharacterModelList()
        {

        }

    }

}

这是另一个类:

public partial class Characters : ContentPage
{
    public Characters(string name, string description)
    {
        InitializeComponent();
        Title = name;
        lbl_Description.Text = description;
    }

    private async void btn_Back_Clicked(object sender, EventArgs e)
    {
        await Navigation.PopAsync();
    }
}

和app(这个没什么特别的):

public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
            MainPage = new NavigationPage(new MainPage());
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
你能告诉我我做错了什么吗?如果需要,我也可以发布xaml。这可能没什么特别的,但作为Xamarin的初学者,我对此疯狂!任何帮助将不胜感激。

编辑:我得到的错误:

  

{System.MissingMethodException:Method   'System.Net.Http.HttpClientHandler.set_AutomaticDecompression'没有   找到。在   Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.CreatePipeline   (System.Collections.Generic.IEnumerable 1[T] handlers) [0x0000a] in <42e24ce875d34485ad11c4f8aebb904a>:0 at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient..ctor (System.Collections.Generic.IEnumerable 1 [T]个处理程序,System.Uri   applicationUri,System.String installationId)[0x00014] in   &lt; 42e24ce875d34485ad11c4f8aebb904a&gt;:0 at   Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor   (System.Uri mobileAppUri,System.Net.Http.HttpMessageHandler []   处理程序)[0x00085]在&lt; 42e24ce875d34485ad11c4f8aebb904a&gt;:0 at   Microsoft.WindowsAzure.MobileServices.MobileServiceClient..ctor   (System.String mobileAppUri,System.Net.Http.HttpMessageHandler []   处理程序)[0x00008]在&lt; 42e24ce875d34485ad11c4f8aebb904a&gt;:0 at   One_Piece.MainPage..ctor()[0x0001b] in   C:\ Users \用户法比奥\桌面\挑战\一   Piece \ One_Piece \ MainPage.xaml.cs:24}

0 个答案:

没有答案