2017-05-19 14 views
0

こんにちは私は、デバイスにインストールされているすべてのアプリケーションのリストを示すxamarinフォームのアプリケーションで作業しています。すぐに起動するために、アプリケーションにショートカットを作成できます。これはすべて私が持っている問題はうまく動作します。私はカードスタイルのxamlレイアウトを作成しようとしていて、アプリのこの部分を開いてこのエラーを表示するときにアプリリストをxamlにバインドします。ポジション31:28。 MarkupExtensionが見つからないxamarinフォームのアプリケーション

編集:私は@Jasonの提案を試してみましたが、私はまだ、このエラーここ

を取得します私の更新のXAMLコード:

 using AppName.Data; 
using System; 
using System.Collections.Generic; 
using Xamarin.Forms; 

namespace AppName 
{ 
    public partial class ListInstalledAppsPage : ContentPage 
    { 
     public ListInstalledAppsPage() 
     { 
      InitializeComponent(); 
      var appsNames = new List<String>(); 
      PackageInterface pkg = DependencyService.Get<PackageInterface>(); 
      var apps = pkg.GetInstalledApps(); 
      foreach (var a in apps) 
      { 
       appsNames.Add(a.Name); 
      } 


      listView.ItemSelected += async (object sender, SelectedItemChangedEventArgs e) => 
      { 
       if (e.SelectedItem == null) 
       { 
        return; //ItemSelected is called on deselection, which results in SelectedItem being set to null 
       } 
       string app = e.SelectedItem.ToString(); 
       string action = await DisplayActionSheet("Add to?", "Cancel", null, "Home", "Math", "Science", "Handwriting"); 
       if (Application.Current.Properties.ContainsKey(action)) 
       { 
        string appsList = Application.Current.Properties[action] as string; 
        if (!appsList.Contains(app)) 
        { 
         if (string.IsNullOrEmpty(appsList)) 
         { 
          appsList = app; 
         } 
         else 
         { 
          appsList += ";" + app; 
         } 
         Application.Current.Properties[action] = appsList; 
        } 
       } 
       else 
       { 
        Application.Current.Properties.Add(action, app); 
       } 
       await Application.Current.SavePropertiesAsync(); 
       await Navigation.PopAsync(); 
       MessagingCenter.Send<ListInstalledAppsPage>(this, "Refresh"); 
      }; 

     } 
    } 
} 
:ここ

<?xml version="1.0" encoding="UTF-8"?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="AppName.ListInstalledAppsPage"> 
    <ListView x:Name="listView" HasUnevenRows="true" ItemSelected="OnItemSelected" BackgroundColor="#d2d5d7"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
     <ViewCell> 
      <Frame IsClippedToBounds="True" 
     HasShadow="True" BackgroundColor="#d2d5d7"> 
         <Frame.OutlineColor> 
     <OnPlatform x:TypeArguments="Color" 
        Android="Gray" 
        iOS="Gray"/> 
    </Frame.OutlineColor> 

<Frame.Margin> 
     <OnPlatform x:TypeArguments="Thickness" 
        Android="10" iOS="10"/> 
    </Frame.Margin> 

          <Frame.Padding> 
     <OnPlatform x:TypeArguments="Thickness" 
        Android="0" iOS="0"/> 
    </Frame.Padding> 
           <Frame.Content> 
       <Frame Padding="15,15,15,15" OutlineColor="Gray" BackgroundColor="White"> 
       <Frame.Content> 
<StackLayout Padding="20,0,0,0" Orientation="Horizontal"> 

        <Label 
          HorizontalOptions="CenterAndExpand" 
          ItemsSource="{appsNames}" 
          FontFamily="OpenSans-Light" 
          FontSize="24"/> 
        </StackLayout> 
       </Frame.Content> 
       </Frame> 
      </Frame.Content> 
      </Frame> 
     </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
    </ListView> 
</ContentPage> 

の背後にある私の更新されたコードです

何か助けが素晴らしいだろう!

ありがとうございます!!!

+0

リストビュー全体をコードの背後に作成している場合、なぜXAMLページがあるのでしょうか?また、LabelにItemsSourceプロパティがなく、Labelに使用しているバインディング構文が完全に無効であるように見えます。 – Jason

+0

@ Jason xamlページを持っている理由は、カードスタイルレイアウトの魔法使いを使うことができるようになっているからです。速い返信をいただきありがとうございます! :) – Phoneswapshop

+0

コードの中にコンテンツを割り当てないでください。これは、XAMLのすべてを上書きします。コードの背後に新しいListViewを作成せず、代わりにXAML ListViewへの参照を使用します。破損したラベルを修正してください。 – Jason

答えて

0

ラベルにappsNamesの文字列を表示するとしますか?

まず、ListViewのItemsSourceをappsNamesに設定する必要があります。バインディングやコードの後ろで行うことができます。

これは、ページのBindingContextをそれ自身に設定していることを前提としています。例えばコンストラクタでは、追加:

BindingContext = this; 

または次のあなたの後ろに、このようなコードでそれを割り当てることができます。

listView.ItemsSource = appsNames; 

その後、このラインは、あなたのXAMLで

<Label HorizontalOptions="CenterAndExpand" 
     ItemsSource="{appsNames}" 
     FontFamily="OpenSans-Light" 
     FontSize="24"/> 

する必要があります
<Label HorizontalOptions="CenterAndExpand" 
     Text="{Binding .}" 
     FontFamily="OpenSans-Light" 
     FontSize="24"/> 

appsNamesはXAMLで何も意味しないし、LabelにItemsSourceプロパティもないため、エラーが発生します。

+0

これは本当にありがとうございました!!!! – Phoneswapshop

関連する問題