2016-05-12 8 views
1

このエラーメッセージが繰り返し表示されます。部分宣言で異なる基本クラスを指定してはいけません。誰かが私にこれの原因となるかもしれないことを教えてもらえますか?ここに私のコードです。部分宣言で異なる基本クラスを指定してはならない

CashAdvancePage.xaml

<?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="ebmsMobile.CashAdvancePage" 
      Title="Cash Advance" 
      BackgroundImage="bg3.jpg"> 
    <Label Text="This is the Cash Advance Page." VerticalOptions="Center" HorizontalOptions="Center" /> 
</ContentPage> 

CashAdvancePage.xaml.cs

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using System.Threading.Tasks; 

using Xamarin.Forms; 

namespace ebmsMobile 
{ 
    public partial class CashAdvancePage : ViewCell 
    { 
     public CashAdvancePage() 
     { 
      //InitializeComponent(); 
      //NavigationPage.SetHasNavigationBar(this, false); 

      var image = new Image 
      { 
       HorizontalOptions = LayoutOptions.Start 
      }; 
      image.SetBinding(Image.SourceProperty, new Binding("ImageUri")); 
      image.WidthRequest = image.HeightRequest = 40; 

      var nameLayout = CreateNameLayout(); 
      var viewLayout = new StackLayout() 
      { 
       Orientation = StackOrientation.Horizontal, 
       Children = { image, nameLayout } 
      }; 
      View = viewLayout; 


     } 

     static StackLayout CreateNameLayout() 
    { 
     var nameLabel = new Label 
     { 
      HorizontalOptions= LayoutOptions.FillAndExpand 
     }; 
     nameLabel.SetBinding(Label.TextProperty, "DisplayName"); 

     var twitterLabel = new Label 
     { 
      HorizontalOptions = LayoutOptions.FillAndExpand, 
      Font = Fonts.Twitter 
     }; 
     twitterLabel.SetBinding(Label.TextProperty, "Twitter"); 

     var nameLayout = new StackLayout() 
     { 
      HorizontalOptions = LayoutOptions.StartAndExpand, 
      Orientation = StackOrientation.Vertical, 
      Children = { nameLabel, twitterLabel } 
     }; 
     return nameLayout; 
    } 
    } 
} 
+0

なぜあなたは.csページでviewcellを継承していますか?私はそれがコンテンツページでなければならないと思う。継承しているクラスは、xamlのルート要素でなければなりません。 –

+0

@Akash Amin私はちょうどそれがContentPageだったインターネット上でそれを見た。しかし、私がContentPageを使用しているとき、 'Xamarin.Forms.View'が '型'であるが、 '変数'のように使用されるというエラーが表示されます。 –

+0

View = viewLayoutの代わりにContent = viewLayoutを使用できます –

答えて

2

をご覧ください。

もう1つの問題は、「viewLayout」をViewではなくContentに割り当てる必要があることです。

using Xamarin.Forms; 

namespace ebmsMobile 
{ 
public partial class CashAdvancePage : ContentPage // derive from ContentPage 
{ 
    public CashAdvancePage() 
    { 
     //InitializeComponent(); 
     //NavigationPage.SetHasNavigationBar(this, false); 

     var image = new Image 
     { 
      HorizontalOptions = LayoutOptions.Start 
     }; 
     image.SetBinding(Image.SourceProperty, new Binding("ImageUri")); 
     image.WidthRequest = image.HeightRequest = 40; 

     var nameLayout = CreateNameLayout(); 
     var viewLayout = new StackLayout() 
     { 
      Orientation = StackOrientation.Horizontal, 
      Children = { image, nameLayout } 
     }; 
     Content = viewLayout; // <-- Set the ViewLayout as Content 


    } 

    static StackLayout CreateNameLayout() 
    { 
     var nameLabel = new Label 
     { 
      HorizontalOptions = LayoutOptions.FillAndExpand 
     }; 
     nameLabel.SetBinding(Label.TextProperty, "DisplayName"); 

     var twitterLabel = new Label 
     { 
      HorizontalOptions = LayoutOptions.FillAndExpand, 
     //  Font = Fonts.Twitter 
     }; 
     twitterLabel.SetBinding(Label.TextProperty, "Twitter"); 

     var nameLayout = new StackLayout() 
     { 
      HorizontalOptions = LayoutOptions.StartAndExpand, 
      Orientation = StackOrientation.Vertical, 
      Children = { nameLabel, twitterLabel } 
     }; 
     return nameLayout; 
    } 
} 
} 
+2

両方とも技術的に問題があり、真実ですが、コードビハインドのすべてのコントロールをインスタンス化して変更すると、XAMLファイルを保持することに意味がないことを指摘する価値があると思いますcontentプロパティ全体:) – irreal

+0

@irreal良い点サー。ありがとう –

+0

@マリウスJunak私の問題を解決するようだサーどうもありがとう。 –

1

あなたがここに二つの異なるものまで混合されています。ページビューのセルを。

コードとXAMLの両方でページとビューの両方のセルを作成することはできますが、それらは別々のものです。

XAMLでコンポーネントを作成するときは、ページまたはビューであるため、ルートノードタイプはサブクラス化するタイプでなければなりません。 部分的なクラスが派生しているクラスを再記述する必要がないため、.csファイルの背後にあるコードは、同じ基本クラスから派生しなければならないか、実際にはコードビハインド内に完全に除外することができます。

したがって、CashAdvanceページ定義では、コードビハインドのクラス定義から「:ViewCell」部分を削除してください。

次に、あなたはおそらく、(あなたがコードでそれを構築する場合は、とにかくXAMLページを使用してのポイントは何で、それ以外の場合は?)XAMLであなたのページを構築する必要があり

をあなたが実際にのために(カスタムviewcellが必要な場合例えば、ListViewの内部で使用するために)、あなたのビューセル用の別の.xamlファイルを作成し、そこに独自のUIを構築します。 これをページXAML内またはコードビハインドから参照できます。 XAMLを使用しての詳細については

、あなたがXAMLファイルにRootelementとしてそれを使用する場合は.csでContentPageから継承する必要the Xamarin XAML documentation

+0

チップのおかげでよろしいです:) –

関連する問題