2017-10-16 19 views
1

私はアプリケーションをテストするためのXamarinのサンプルフォーム "TableView"を使用していますが、廃止されたセクションImageSource = Device.OnPlatformはswitch文で置き換えられました。ここでは問題はありませんが、情報は豊富ですが、私には特有の問題があり、問題を見ることができません。Xamarin.Forms ImageSource = Device.OnPlatform廃止されました

私が追加しているコードは現在、以下のソースでコメントアウトされており、このようにして、もちろん画像なしでコンパイルされます。私がコメント欄を削除すると、35行目にエラーが表示されます}。 最後のブレークのすぐ下にある中括弧を強調表示すると、その一致、switch()が認識されます。その下にある中括弧を強調表示すると、それは上のPublic SearchPage()の一部であると考えられます。 スイッチの何かが問題を引き起こしていますが、私はそれを見ることができません。

私は、誰かがこの問題に遭遇し、回答を得たいと考えています。詳細が必要な場合はお知らせください。

using System; 
using System.Collections.Generic; 
using System.Text; 

using Xamarin.Forms; 
//using static System.Net.Mime.MediaTypeNames; 

namespace MiddleMeeter 
{ 
    class SearchPage : ContentPage 
    { 
     public SearchPage() 
     { 
      Label header = new Label 
      { 
       Text = "TableView for a form", 
       FontSize = 30, 
       FontAttributes = FontAttributes.Bold, 
       HorizontalOptions = LayoutOptions.Center 
      }; 

      TableView tableView = new TableView 
      { 
       Intent = TableIntent.Form, 
       Root = new TableRoot("TableView Title") 
       { 
        new TableSection("Table Section") 
        { 
         new TextCell 
         { 
          Text = "Text Cell", 
          Detail = "With Detail Text", 
         }, 
         new ImageCell 
         { 
          /********************************************************************************************** 
          switch (Device.RuntimePlatform) 
          { 
           case Device.iOS: 
           ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png")); 
            break; 
           case Device.Android: 
            ImageSource.FromFile("waterfront.jpg"); 
            break; 
           case Device.WinPhone: 
            ImageSource.FromFile("Images/waterfront.jpg"); 
            break; 
           default: 
            ImageSource.FromFile("Images/waterfront.jpg"); 
            break; 
          }, 
          */////////////////////////////////////////////////////////////////////////////////////////////// 

          Text = "Image Cell", 
          Detail = "With Detail Text", 
         }, 
         new SwitchCell 
         { 
          Text = "Switch Cell" 
         }, 
         new EntryCell 
         { 
          Label = "Entry Cell", 
          Placeholder = "Type text here" 
         }, 
         new ViewCell 
         { 
          View = new Label 
          { 
           Text = "A View Cell can be anything you want!" 
          } 
         } 
        }, 
       } 
      }; 

      // Build the page. 
      this.Content = new StackLayout 
      { 
       Children = 
       { 
        header, 
        tableView 
       } 
      }; 
     } 
    } 
} 

答えて

0

は答えた:おかげScryptique

は、私は、フォームのギャラリーのためにXamarinによって提供されるサンプルを置き換えるために使用しています正確なコードを投稿したいです - - > 'フォームのTableView'。

using System; 
using System.Collections.Generic; 
using System.Text; 

using Xamarin.Forms; 
//using static System.Net.Mime.MediaTypeNames; 

namespace MiddleMeeter 
{ 
    class SearchPage : ContentPage 
    { 
     public SearchPage() 
     { 
      Label header = new Label 
      { 
       Text = "TableView for a form", 
       FontSize = 30, 
       FontAttributes = FontAttributes.Bold, 
       HorizontalOptions = LayoutOptions.Center 
      }; 

      TableView tableView = new TableView 
      { 
       Intent = TableIntent.Form, 
       Root = new TableRoot("TableView Title") 
       { 
        new TableSection("Table Section") 
        { 
         new TextCell 
         { 
          Text = "Text Cell", 
          Detail = "With Detail Text", 
         }, 
         new ImageCell 
         { 
          // This is the call to method getSource() 
          ImageSource = getSource(), 
          Text = "Image Cell", 
          Detail = "With Detail Text", 
         }, 
         new SwitchCell 
         { 
          Text = "Switch Cell" 
         }, 
         new EntryCell 
         { 
          Label = "Entry Cell", 
          Placeholder = "Type text here" 
         }, 
         new ViewCell 
         { 
          View = new Label 
          { 
           Text = "A View Cell can be anything you want!" 
          } 
         } 
        }, 
       } 
      }; 

      // Build the page. 
      this.Content = new StackLayout 
      { 
       Children = 
       { 
        header, 
        tableView, 
       } 
      }; 


     } 

     // Method to get the format to retreive the image for Platform specific detaisl 
     private ImageSource getSource() 
     { 
      switch (Device.RuntimePlatform) 
      { 
       case Device.iOS: 
        return ImageSource.FromUri(new Uri("https://www.xamarin.com/content/images/pages/branding/assets/xamagon.png")); 
       case Device.Android: 
        return ImageSource.FromFile("Icon.png"); 
       case Device.WinPhone: 
        return ImageSource.FromFile("Images/waterfront.jpg"); 
       default: 
        return ImageSource.FromFile("Images/waterfront.jpg"); 
      } 
     } 
    } 
} 
2

私はこのようなオブジェクトの初期化子でswitchステートメントをサポートしているとは思いません。これを解決する最も良い方法は、switchステートメントをメソッドにリファクタリングし、それを使ってImageCellを初期化することです。

ImageSource GetSource() 
{ 
    switch (Device.RuntimePlatform) 
    { 
     case Device.iOS: 
      return ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png")); 
     case Device.Android: 
      return ImageSource.FromFile("waterfront.jpg"); 
     case Device.WinPhone: 
      return ImageSource.FromFile("Images/waterfront.jpg"); 
     default: 
      return ImageSource.FromFile("Images/waterfront.jpg"); 
    } 
} 

そして初期化子でそれを使用する:

new ImageCell 
{ 
    ImageSource = GetSource() 
} 
+0

これはまさに必要なものです。私はXamarinが彼らのアプリの変化について明らかにしたいと思っていますが、これが解決してうれしいです。ありがとう –

関連する問題