2017-10-16 3 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

은 내가 양식 갤러리에 대한 자 마린에서 제공하는 샘플을 대체하기 위해 사용하고있는 정확한 코드를 게시하고 싶었다 - -> '폼의 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

저는 C#이 객체 초기화 프로그램에서 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이 앱의 변경 사항에 대해 분명히했으면 좋겠지 만 해결해 주어 기쁩니다. 감사 –

관련 문제