开发者

View with a baseclass in WP7 and MVVMLight

开发者 https://www.devze.com 2023-02-01 07:53 出处:网络
I\'m having multiple views in my project and want them to derive from a base class where some navigation logic is handled. This logic doesn\'t belong in the VM, so I\'ve got it placed in the View.

I'm having multiple views in my project and want them to derive from a base class where some navigation logic is handled. This logic doesn't belong in the VM, so I've got it placed in the View.

Now when I'm trying to change the base class of the view I'm receiving the following error:

Partial declarations of 'ProjectName.Results' must not specify different base classes.

The only thing I've changed is:

public partial class Results : PhoneApplicationPage

to:

public partial class Results : BaseView

I can't find any other decle开发者_开发百科ration of the Results class in my project. Perhaps MVVMLight generates something while building.

Is it possible to let the views derive from a base class? It should be, but I can't get it to work.


Assuming that your BaseView inherits PhoneApplicationPage like following:

public class BaseView : PhoneApplicationPage
{
    //...
}

After changing from:

public partial class Results : PhoneApplicationPage

To:

public partial class Results : BaseView

Also change your XAML from something like:

<phone:PhoneApplicationPage x:Class="WindowsPhonePivotApplication1.Results"

To:

<local:BaseView x:Class="WindowsPhonePivotApplication1.Results"

also add a xml namespace like following:

xmlns:local="clr-namespace:WindowsPhonePivotApplication1"


Your Results class declaration is met in XAML as well as in code-behind file what's why you got this error. Yes It's possible to inherit views classes from base one but I think you'd better use composition to embed your navigation logic, for instance you may create a custom control for it and insert it in all your views.

0

精彩评论

暂无评论...
验证码 换一张
取 消