I'm currently trying to customize a Visual Studio Isolated Shell so it opens a XAML file and its designer without a solution or a project. Therefore, for the designer to load, Visual Studio need to recognize every xaml tag in the XAML file or it won't load telling me that the document contains errors.
I'm currently trying to manually load an assembly from Telerik's control set (RadControls) without a reference since I need to use the designer without a solution/project.
Is it possible to manually load an assembly in XAML from a "custom" .dll like Telerik's without a VS project reference so the custom controls from the assembly are recognized by Visual Studio at design time (in order to use the WPF designer)?
Thanks!
SatixX
maybe you can read the namespace references out and try to resolve the assemblies in GAC and/or any other location (think of standard paths .NET itselfs looks for assemblies). Then try to load them with reflection. Afterwards you then could try to load the XAML. But: if an assembly isn't found, you should throw an error and stop loading the XAML. Also, considering an appdomain might be well suited because you can unload it again.
-sa
Related
I would like to embed compiled XAML into an assembly as BAML2006.
If the Embedded Resource MSBuild action is selected, the XAML file gets embedded into the assembly as a text resource that can be read like any other loose XAML resource. However, loose XAML has some serious limitations when it comes to referenced namespaces, most cripplingly, any namespace referred to by its [XmlnsDefinitionAttribute] must be loaded into the AppDomain before the loose XAML is parsed. In contrast, embedded BAML does not suffer from this, as the assembly containing the namespace is added to the list of referenced assemblies and is loaded by the AppDomain automatically before any code starts running.
If the Page MSBuild task is selected, XAML gets "compiled" into BAML2006 and is embedded to the .resources.g of the containing assembly. However, compilation will fail if the WindowsBase, PresentationCode and PresentationFramework assemblies are not referenced. As I am working on a project which uses XAML but not WPF (we load object graphs with XamlObjectWriter and custom markup extensions, but reuse the Visual Studio some of XAML editor infrastructure for IntelliSense support), I would like to avoid depending on these libraries.
Is there any way to make MSBuild embed BAML and add required assembly references without depending on WPF?
I guess Workflow Foundation uses a similar approach, but I haven't been able to find any information.
I have a winform usercontrol than I want to add to wpf project.
I added the relevant references (WindowsFormsIntegration, SystemWindowsForms and my user control dll) and added this row in my XAML:
xmlns:MyControl="clr-namespace:xx.xx.xx;assembly=xx.xx"
And then this:
<WindowsFormsHost><MyControl:control></MyControl:control></WindowsFormsHost>
When I write "MyControl:" the "control" is automated show up that mean VS recognize the control and all references added ok... but when I compile the project this give me the error in the title.
Edit
Its very strange when I'm compile the all project i've got error "The type or namespace name "xx' could not be found..."
but I added all the refernces and the VS recognize the namespace so why the compiler don't found them? If this problem will be solved I beleive the other problem also will disappear.
The solution is: Go to your project properties and change the Target Framework from Client Profile to the full version of the .Net you are using, see the image below. This problem happens if your DLL targets the full .NET Framework, and your WPF Application (main project) targets .Net Client Profile.
This happened to me when I included the assembly name in the namespace definition, but both controls were in the same assembly. Just removing the assembly part of the namespace declaration solved it.
Visual Studio will load the reference only for reflection so it will show correct intellisense correctly. But in order to compile, compiler will need all the dlls that your referenced dll is dependent on. So visual studio will show intellisense for mycontrol as it can find it in reference. But your myontrol may reference other dlls which you may not have added. You will have to add dependent references of mycontrol in your project too.
It could also be that the target framework is different between your projects. We host a class library dll with the WPF pages, and it was targeted to 'Any CPU', but the host application was targeted to 'x86'. Once they matched, the problem went away.
I ran into the same "The type or namespace name 'xx' could not be found..." issue.
It disappears when I moved my Visual Studio files on a local drive. They were stored on a shared network directory before. I dont know the root cause of this, but at least I can have my designer running now.
I've encountered this problem before and replacing <MyControl:control></MyControl:control> with just <MyControl:control/> fixed it for me.
No idea why though. It seems like the first form is only for controls which can contain other controls.
I have a class library that I created using the "Class Library" project template. If I right-click on this library in Solution Explorer and select "Add > User Control", Visual Studio adds a WinForms UserControl. That's not what I want -- I want "Add > User Control" to add a WPF user control.
I've already added references to the WPF assemblies (WindowsBase, PresentationFramework, and PresentationCore), and I already have some WPF UserControls in this library, and everything compiles. My library does not have references to the WinForms assemblies (System.Drawing and System.Windows.Forms). But apparently the proper references are not enough of a clue for Visual Studio, because when I try Add > User Control, it adds the WinForms references to my project, and then creates a WinForms UserControl.
I can add a WPF User Control to my WPF Application project, and then move it into my library. But that's a pain, and I'd rather have it work properly in the first place.
I think I'm probably missing some kind of arcane XML element in my .csproj file that tells Visual Studio which designer to use by default, and if I add the right XML element with the right cryptic GUID, it will start working properly. If I could create a new WPF Control Library, I could probably compare the two project files and figure this out. However, I'm using Visual C# Express, which doesn't have a template for a WPF Control Library project, so I'm out of luck there.
What do I need to do to my Class Library's .csproj file so that VS2010's Add > New User Control will add a WPF UserControl?
There are sub-projects class ids in the project file that affect the Visual Studio context menus and how the project behaves in general. The easiest thing to do is to recreate the project as a:
WPF User Control Library
instead of a "Class Library". It is possible if you already created the project to edit in the sub-project class ids by hand by opening the ".csproj" file in a text editor such as Visual Studio itself but its easy to cause more damage than you fix that way.
I believe but haven't test that another type of library will also work:
WPF Custom Control Library
which is intended to hold other types of controls than UserControl objects but being a WPF sub-project type the context menus also work correctly for the use case you are describing.
Edit:
For completeness, I've just tested how to manually add the sub-project GUIDS. Add this line to the first PropertyGroup in the .csproj file:
<PropertyGroup>
...
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
Not tested with Visual Studio Express.
I recently added a control library project to my Silverlight app's solution, so the solution now has three projects:
SLClient
SLClient.Controls
SLClient.Web
SLClient has a project reference to SLClient.Controls, which contains the following:
Themes
Generic.xaml (contains default CustomTextBox template)
Templates.xaml (contains additional template used by CustomTextBox)
CustomTextBox.cs (Descended from System.Windows.Controls.Control)
The xaml files above have Build Action of "Resource" and an empty Custom Tool property. Everything builds fine, but when the XAML files (a view, and my App.xaml that merges in SLClient.Controls's Templates.xaml) in SLClient that reference SLClient.Controls are open, Visual Studio tells shows an error in the "xmlns:SLClient_Controls="clr-namespace:SLClient.Controls;assembly=SLClient.Controls" line:
Assembly "SLClient.Controls" was not found. Verify that you are not missing an assembly reference [...]
Update: The page not loading, which I had previously mentioned, was caused by a different error in my XAML. I still get this error though, and would still like to know what's causing it. Is it a bug in the XAML compiler? The code generated from the XAML compiles fine.
If you have added references in SLClient.Controls's project , then currently those assemblies are not automatically referenced in SLClient as expected as they do in normal .NET 2.0 projects.
So please verify that all the references in SLClient.Control's project are also manually added in SLClient project as well. For example if you add System.Windows.Toolkit reference in SLClient.Control, then you will also have to add the same reference in SLClient.
This is known bug and I have already reported this bug to Microsoft. And its still under processing.
sounds like a hokey reference. Try this:
Delete the reference in the project and the xmlns ref in the XAML.
Clean and rebuild all the projects
Re-add the project reference.
Build
Re-add the XAML xmlns reference
Rebuild
HTH,
Mark
i have a project that i am doing and i need to share the code between silverlight and WPF Assembly problem is that even though the wpf assembly is the owner of that file
and the silverlight assembly only has a link to the file, all of the build actions are page everything is correct. if i make the silverlight assembly the owner then silverlight works and wpf doesnt, and currently with wpf being the owner i dont get any errors at all it just never styles the control like it cannot find it..
Note: both projects exists in the same solution.
this scenario builds and runs fine
wpf project
|__Themes
|__Generic.xaml
|__SomeControl.cs
this scenario builds and runs but will not display the control
if i change them from linked to normal it will work fine.
i just want to share this source code and not have multiple versions of the same file floating around.
SilverlightProject
|__Themes
|__"Linked"Generic.xaml
|__"Linked"SomeControl.cs
sorry for my corny Tree view representation
+++++++ UPDATE +++++++++
i have noticed when using any linked file regardless of if it is silverlight or WPF
the link file will not build into the Themes folder in the resource only the root.
i used reflector to see where my resources ended up after compilation of the assembly including the linked file and they ended up in the root , so with that being said. is there a way to prevent this or a fix for this if this is indeed non intended behavior .
i would really love to get this figured out as it has been driving me insane for a while now.
Silverlight XAML and WPF XAML do not have the same namespace - so they aren't directly reusable.
My mistake - you're right - now with Silverlight 3 the namespaces are the same:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml
What is the Build Action in the Property Pane for the XAML?