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?
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"
>
Related
I'm using VS2013 Express. I'm quite new in WPF and MVVM. I've downloaded mvvmlight using NuGet to my project. I'm tryinng to use GalaSoft_MvvmLight_Command:EventToCommand. As far as I know, I have to add reference in xaml by adding namespace:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight"
But, unfortunatelly I get error, that says:
The tag 'EventToCommand' does not exist in XML namespace
'clr-namespace:GalaSoft.MvvmLight;assembly=GalaSoft.MvvmLight'.
I've found some information, that I have to include GalaSoft.MvvmLight.WPF45 assembly, but I don't see this dll in packages\MvvmLightLibs.5.0.0.1\lib\ folder. There are many folders, for each .NET version etc, but each of these assemblies names are the same, without WPF45 sufix.What is going on? Where do I find this GalaSoft.MvvmLight.WPF45.dll assembly? Or maybe in version 5 was some changes made in names?
Edit:
Using object browser I found that EventToCommand is in GalaSoft.MvvmLight.Platform assembly in GalaSoft.MvvmLight.Command namespace. So I did
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
I can compile project now, but I still get errors in xaml (what is weird):
A value of type 'EventToCommand' cannot be added to a collection or dictionary of type 'TriggerActionCollection'
and
The type 'EventToCommand' from assembly 'GalaSoft.MvvmLight.Platform' is built with an older version of the Blend SDK, and is not supported in a Windows Presentation Framework 4 project.
and xaml editor can't display window properly (invalid markup).
Edit2:
Solution for invalid markup.
After I've changed the namespace to xmlns:cmd="http://www.galasoft.ch/mvvmlight" I also change project's target framework from 4.5 to 3.5. IDE shows an error about there are few NuGet packages that target other framework, so I returned to 4.5 - and it magically works now ;). Thanks all for help.
Here's how its done now in your XAML assuming you've got Version 4.0.0. Beat 1 or higher:
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
I found this at the bottom the release notes here: http://www.mvvmlight.net/installing/changes/
Details
XmlnsDefinitionAttribute for GalaSoft.MvvmLight.Command in Extras assembly
Thanks to the addition of XmlnsDefinitionAttribute, you can simplify the inclusion of the MVVM Light EventToCommand action in XAML. See the before and after below:
Before:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
After:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"
x:Class="MvvmLight4.MainPage">
EventToCommand exists in the Extras assembly.
Try:
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
More Information:
To determine the assembly a class falls in, I usually Go To Definition and the assembly is referenced in the region at the top of the [from metadata] code file.
I get this error when running the application.
XmlParseException Occured
Could not load file or assembly 'System.Windows.Controls.DataVisualization.Toolkit, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified
XAML
<UserControl x:Class="myNamespace.Views.ChartView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chart="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Label Margin="10" Content="Scatter series" />
<chart:ScatterSeries DependentValueBinding="{Binding Value}"
IndependentValueBinding="{Binding Key}"
ItemsSource="{Binding PlotValues}" />
</Grid>
ViewModel:
public ObservableCollection<KeyValuePair<double, double>> PlotValues
{
get { return _plotValues; }
set { _plotValues = value; }
}
I think your problem is related to an issue/bug with the dependency detection in Visual Studio or MSBuild (related bug can be found here).
I've been able to reproduce your problem by doing the following:
Create a new WPF application
Create a new UserControl Library
Install the System.Windows.Controls.DataVisualization.Toolkit NuGet package on the UserControl Library (not the WPF application)
Add the scatter series
Add the custom user control containing the scatter series to the main window and running the application
The problem seems to be that without any reference to anything in the code (outside XAML), Visual Studio assumes that you are not using the assembly and therefore does not copy it to the output directory of the main application/project referencing it. More details can be found here, although these are references in ordinary code (C#, not XAML).
There are three workarounds which seems to make Visual Studio detect the dependency which I know of:
Give the control a name, and any name will do (my preferred solution)
Add a C# code reference to a controller in the Control Library (dummy code)
Add the NuGet or .dll reference to the actual application which is run
After having struggled with the same issue myself for a few hours, I believe to have discovered that Visual Studio is unable to detect the dependency on the dll based on a single usage directly in the XAML without a code reference (or a Name, which creates a code reference for you, allowing you to access the controller in the code-behind).
Edit:
I have reported this issue to Microsoft through Connect, so that they hopefully will fix it.
Immediately after adding a brand new, untouched WPF window to my IronPython 2.7 project in VS2013 (with Python Tools for VS 2.0.11016), it tells me "Invalid Markup" in the design window, and the error list shows:
Window is not supported in a Windows Presentation Foundation (WPF) project.
Grid is not supported in a Windows Presentation Foundation (WPF) project.
The XAML window has this innocuous looking code in it:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
</Grid>
</Window>
Does Python tools for VS not really support form creation? Did I forget to configure something?
The project was started as an "IronPython Windows Forms Application" rather than an "IronPython WPF Application" so it was missing the relevant references:
PresentationCore
PresentationFramework
WindowsBase
Adding them makes WPF forms functional, or just recreating the project.
If all of those references appear to be in the project, removing/readding some might help. Another user reported he had to do so for 'PresentationFramework'; perhaps there's a couple that have the same name?
I just spent several hours on an issue when using VS2012, WPF 4.5 and design-time data, specifically the DesignInstance attribute.
Goal: I wanted to have design-time data support in my WPF project (MVVM-based), both in VS2012 and Blend, and I could not for the life of me make the MVVMLight approach work consistently.
So I tried to change to "just" using the built-in support for design-time data, using the markup extension provided with Blend.
Problem: Consider the following code:
<Window x:Class="Nova.View.AlertsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Nova.View"
xmlns:vm="clr-namespace:Nova.ViewModel"
mc:Ignorable="d"
DataContext="{Binding Alerts, Source={StaticResource Locator}}"
d:DataContext="{d:DesignInstance vm:DesignAlertsViewModel, IsDesignTimeCreatable=True}"
... />
Both VS2012 and Blend reports "the name DesignAlertsViewModel does not exist in the namespace clr-namespace:Nova.ViewModel", even though intellisense resolves it just fine, and you have checked a thousand times that the namespace and class name are both correct.
I ran into this error myself in VS2013 then found this question. After searching more, I found an answer that helped me solve it.
instead of
d:DataContext="{d:DesignInstance vm:DesignAlertsViewModel, IsDesignTimeCreatable=True}"
use
d:DataContext="{d:DesignInstance d:Type=vm:DesignAlertsViewModel, IsDesignTimeCreatable=True}"
I was using "...d:DesignInstance Type=vm:..." and that displays the same error described above. As soon as I add "d:" everything works.
Here is the thread I found that helped.
https://stackoverflow.com/a/21690404/2892400
Check if the "Platform target" in your build configuration is set to "AnyCPU". My was set to "x64", so the designer was complaining about the missing type.
VS is running in 32 bit so maybe there is an issue with executing code from 64 bit assemblies.
I found the solution when trying to open my UserControl in "Blend for Visual Studio". It displayed an neat exception to me.
P.S.: After using the accepted answer: Use "d:Type=vm:DesignAlertsViewModel" instead of "vm:DesignAlertsViewModel" my control was visible, but no example data was displayed.
Workaround: Make sure that the design-time data class is in the same namespace as the View itself. Once I moved my DesignAlertsViewModel to the View namespace, both the VS2012 and Blend designer immediately started working with the design-time data.
Update: This is a workaround for now, until I get to the bottom of the issues. However, in my case, this is the only way to make design-time data work consistently. Of course, if you go down this route you change the class names since - clearly - the DesignAlertsViewModel is no longer a view model. It is now simply a POCO containing design-time data. So perhaps AlertsDesignData would be a better name. I'm not overly happy with the fact my design-time data lives under my View namespace, but it works.
I also encourage you to take a look at Laurent's article from MSDN Magazine, April 2013. I like this approach, since it exercises the MVVM pattern a lot more: The design time data service/provider is injected via IOC, so your view models will get "exercised" even at design time.
Update 2: After spending yet another 4 hours on this, I think the jury is still out on which approach is the better: Should we go with simple POCO data classes or the MVVMLight approach, using IOC for design-time data services? The former is simple and requires less code, the latter is more true to the MVVM approach, and exercises the real view models to some degree and could possibly reveal some bugs along the way.
Also, I did have to restart VS a couple of times during my refactoring to the MVVMLight approach - design-time data simply disappeared and came back after a VS restart. However, right now it seems stable enough, and I cannot pinpoint this any further.
I've found that DesignInstance is not working in my .NET 3.5 and .NET 4.0 projects, whereas it works in >= .NET 4.5 project (the projects are the same, they share the same files by using links).
I am using a base Window class in a WPF project. In the code behind C# file the assembly to the base type is referenced and fine. In the XAML is looks like this:
<MyNamespace:WindowBase x:Class="MyNamespace.Applications.UserInterface.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MyNamespace="clr-namespace:MyNamespace.Somewhere;assembly=MyNamespace.Common"
Title="MainWindow" Height="350" Width="525">
<Grid>
</Grid>
The solution compiles fine and I can run it. I just can't use the designer in VS 2010. It throws the following exception: The type'MyNameSpace:WindowBase' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Well. they have been. I can't understand what this issue is. This particular base class is used in other projects just fine. I grabbed it for a new project and I can't use the designer. Very frustrating.
Found this problem just recently (this answer upgraded from a comment).
If you copy the dll from a network path, you must right click on the file in Windows Explorer, select Properties, then 'unblock'; there is a hidden NTFS stream associated with the file, and many files when you download from the 'net or copy from a network path, for security reasons.
Only the designer complains, yet the project builds and runs fine: weird isn't it?!
Whenever the designer is acting up against me - the first thing I do is clear the obj-folders in the project and rebuild. Sometimes they seem to go out of sync for some reason (usually when I'm drag-dropping a lot of files and renaming visual items).
I dont't know if its the same issue but in VS2008 I tried to make abstract UserControls but had to change this because the designer didnt't support any abstract base classes (however the solution was compilable and also worked as excpected).
Fixed. The library that contained my base class resided on a drive on the network that I did not have permissions to. That seemed to have no affect on VS 2008 as it worked, but VS 2010 apparently took exception to that when the designer tried to load it. Weird.