2016-07-28 83 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的邮政编码。 –