PageFunction is not supported in a Windows Presentation Foundation project

南笙酒味 提交于 2019-12-08 05:45:46

问题


I'm aware this is the same issue as raised in "PageFunction is not supported in a Windows Presentation Foundation (WPF) project" 2012 - however, I'm unsure as to how to apply the workaround mentioned there, and thought it may be more appropriate to raise this as a separate question. Apologies in advance if this is against the site ethos.

To summarise the problem: I have a C# Visual Studio 2010 WPF project that's a couple of years old, which I'm now trying to open in Visual Studio 2012. Although the project still builds and runs fine, I need to edit the XAML markup, and the Design view in VS2012 complains of "Invalid Markup". The exact error it's tripping up on is:

Page Function is not supported in a Windows Presentation Foundation (WPF) project

The start of the XAML looks like:

 <PageFunction
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyNamespace" 
    x:Class="MyProject.WizardPage1"
    x:TypeArguments="local:WizardResult"
    KeepAlive="True"
    WindowTitle="My Project" Height="350" ShowsNavigationUI="False" Width="700" >

As mentioned in the original question, there are reports of this exact issue on this Microsoft page. There is a workaround mentioned involving "ViewBase", but I cannot see how this relates to the PageFunction problem (I'm very new to XAML so I may be missing something simple).

I've tried opening the project in Blend for VS2012 (the new Preview version that supports non-Windows 8 projects), but that gives the same error about PageFunction not being supported. The recent Update 1 for VS2012 hasn't fixed the problem either.

Can anyone advise what I need to change in my XAML or code-behind in order to be able to visually edit this page?

Or should I give up and just re-download VS2010 in order to edit this project?


回答1:


Based on the workaround, you'll need to create a class which derives from PageFunction<WizardResult>, and then update your XAML to inherit from that class.

Class:

public class WizardResultPageFunction : PageFunction<WizardResult>
{
}

Code-behind: Either change the class to inherit from your new class, or remove the base-class declaration completely and let the XAML define the base class:

public partial class WizardPage1
// or: 
// public partial class WizardPage1 : WizardResultPageFunction 
{
   ...
}

XAML: Replace the PageFunction with local:WizardResultPageFunction and remove the x:TypeArguments attribute:

<local:WizardResultPageFunction 
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:local="clr-namespace:MyNamespace" 
   x:Class="MyProject.WizardPage1"
   KeepAlive="True"
   WindowTitle="My Project" Height="350" ShowsNavigationUI="False" Width="700"
>


来源:https://stackoverflow.com/questions/13585868/pagefunction-is-not-supported-in-a-windows-presentation-foundation-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!