2016-07-28 65 views
0

我有一個問題到Xamarin,我發現Xamarin論壇上的類似問題。這裏是enter link description here。但我沒有得到任何解決方案。任何人都可以幫我解決這個問題。通用在自定義頁面(XAML)

另一個論壇鏈接:Another Xamarin forum link

- 更新

這裏是自動生成的代碼

namespace MyDemo.App.Views { 
    using System; 
    using Xamarin.Forms; 
    using Xamarin.Forms.Xaml; 


    public partial class SignInView : global::MyDemo.App.Views.BaseView { 

     [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")] 
     private void InitializeComponent() { 
      this.LoadFromXaml(typeof(SignInView)); 
     } 
    } } 

回答

0

如果我理解正確的話,我會建議你使用:

public class SomePage : SomeGenericPage<SomeViewModel> { } 

public partial class SomeAnotherPage : SomePage 
{ 
    public SomeAnotherPage() 
    { 
     InitializeComponent(); 
    } 
} 

我的SomePage有通用T財產ViewModel,然後我可以從SomeAnotherPage達到它。 ViewModel屬性將有類型SomeViewModel

public class SomeGenericPage<T> : ContentPage where T : SomeBaseViewModel, new() 
{ 
    readonly T _viewModel; 
    public T ViewModel => _viewModel; 

    public SomeGenericPage() 
    { 
     _viewModel = new T(); 
     BindingContext = _viewModel; 
    } 
} 
+0

嗨葉戈爾, 但這裏在我的情況。 公開密碼局部類SignInView:BaseView ,ISignInView {//此處某些代碼爲 } 可能是由於xaml標記而產生此問題。但我知道如何解決它。 –

+0

您可以將代碼添加到問題中以使其更具可讀性嗎? –

+0

請注意您SignInView的郵政編碼。 –