在 WP7 和 MVVMLight 中使用基类查看

发布于 2024-10-09 09:50:32 字数 453 浏览 0 评论 0原文

我的项目中有多个视图,并希望它们派生自处理某些导航逻辑的基类。这个逻辑不属于虚拟机,所以我把它放在视图中。

现在,当我尝试更改视图的基类时,我收到以下错误:

部分声明 不得指定“ProjectName.Results” 不同的基类。

我唯一改变的是

public partial class Results : PhoneApplicationPage

public partial class Results : BaseView

我在我的项目中找不到 Results 类的任何其他 declaration。也许 MVVMLight 在构建时会生成一些东西。

是否可以让视图派生自基类?应该是这样,但我无法让它发挥作用。

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 decleration 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-10-16 09:50:32

假设您的BaseView继承PhoneApplicationPage,如下所示:

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

更改自:

public partial class Results : PhoneApplicationPage

To:

public partial class Results : BaseView

同时将您的XAML从以下内容更改为:

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

To:

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

还添加一个xml命名空间如下:

xmlns:local="clr-namespace:WindowsPhonePivotApplication1"

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"
橘寄 2024-10-16 09:50:32

您的 Results 类声明在 XAML 以及代码隐藏文件中得到满足,这就是您收到此错误的原因。是的,可以从基类继承视图类,但我认为您最好使用组合来嵌入导航逻辑,例如您可以为其创建一个自定义控件并将其插入到所有视图中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文