VisualStateManager present both in WPF Toolkit and PresentationFramework - How to resolve - wpf

I have to use VisualStateManager class in my WPF window, but as I have referenced the assemblies of both WPF Toolkit and PresentationFramework.dll in my project, C# is not able to resolve the VisualStateManager class and gives the compile error like -
"The type exists in both 'PresentationFramework.dll' and 'WPFToolkit.dll'" and I am not able to proceed.
How to tell C# compiler to use VisualStateManager class from either of the assemblies and get the project to compile successfully?

Since the .NET4.0, the WPF Toolkit has been included in the framework. You should be able to remove WPF Toolkit, update some namespaces and the application still compile.
This is an approach we have taken in a project where we recently upgraded from .NET3.5 to .NET 4.0
Best regards,

I had a similar problem, not to do with the VisualStateManager but with the TemplateVisualStateAttribute I was using for one of my custom classes.
Changing the WPFToolkit project reference alias fixed this for me, as per this question

I ran into the same problem, I can not remove the ToolKit because I need the AutoCompleteBox control, and I don not want to include and modify the toolkit source code; so the solution I used was using an extern alias for the toolkit reference.
To do this in Visual Studio right click on the WPFToolkit reference and select properties >> then change the "alias" field to WpfToolKit or any alias of your choice.

Related

Build Ribbon in full MVVM with Dot Net 4.5

we have several applications in FULL MVVM using the Ribbon from Microsoft. And it works fine, it's a great and flexible component :)
I was surprised to have to build my own templates and bindings to be able to use the ribbon in MVVM (I didn't find those files anywhere).
We are still using the Ribbon DLL from Microsoft (released around 2010 ) and can't switch to the ribbon existing in the Framework because it doesn't work with our Templates/bindings. Nothing happens/appears. Using the XAML description, everything is fine. I'm probably missing something. Does someone use it in full MVVM and which approach did you use to get it working ? Does the Framework contains the Templates and bindings hided somewhere ?
To summarize, how to use the ribbon included in the 4.5 Framework in FULL MVVM ?
Thanks for your help guys :)
If you target .NET Framework 4.5 or later you could add a reference to System.Windows.Controls.Ribbon.dll and use the built-in RibbonControl as-is:
<Ribbon />
You should be able to use this one more or less the exact same way as you use your current version. The templating of a control has nothing to do with MVVM. And of course the control comes with a default template.

Extended DataGrid in Silverlight

How can I add this (ExtendedDataGrid) to my Silverlight project ?
Here is the link to the project I am referring to
http://wpfextendeddatagrid.codeplex.com
Error is:
You can't add a reference to ExtendedGrid.dll as it was not built
against the Silvelright runtime. Silverlight projects will only work
with Silverlight assemblies.
That project was built for WPF and not Silverlight.
This is extended version of WPF toolkit DataGrid control.
Please note: As code of wpf datatgrid in wpftoolkit is moved inside
ExtendedDataGrid project , kindly update Microsoft.Windows.Controls
namespace to ExtendedGrid.Microsoft.Windows.Controls to use existing
objects.
The error message you included in your post states as much.
Silvelright projects will only work with Silvelright assemblies
Remember Silverlight is a stripped down version of .Net used for the browser plugin, and as such will not work with full version of .Net.
Unless you actually go into the source code of that project and try to port it to silverlight then there is currently no other way for you to add that project to your Silverlight project.
I would advise looking into the Silvelright toolkit and it's datagrid. It may not be as full featured as the one you are trying to reference but it covers the basic requirements for a datagrid in silverlight. There are also some open sourced versions that have been extended for silvelright.

DataGridHeaderBorder missing in System.Windows.Controls

Recently i moved my project from .Net3.5 to .Net4. In earlier version to use DataGrid, i was using wpfToolkit and its working fine. But after moving to .Net4 i don't want to explicitly add the refernce to my toolkit since DataGrid has been moved under Controls namespace.
But, all the related references have been moved except for the DataGridHeaderBorder under Controls namespace. To use this we have to explicitly ad reference to PresentationFramework.Aero. I referred to these URL's -
WPF4 DataGridHeaderBorder in a xaml Style
https://connect.microsoft.com/VisualStudio/feedback/details/584894/wpf4-datagridheaderborder-in-a-xaml-style
But i can't add the PresentationFramework.Aero to our project since Aero theme may not be present for all the target environments. So, is there any workaround i can try to get it working? Any how can i get the code from assembly PresentationFramework.Aero for DataGridHeaderBorder so that i can override or subclass it in my code. Any help?
I think you could download latest source code of WPFToolkit and extract DataGridHeaderBorder styles from it.
It has DataGrid\Microsoft\Windows\Controls\DataGridHeaderBorder.cs and corresponding Aero, Classic, Luna themes in DataGrid\Themes\* too.

Errors when referencing Silverlight class library from WPF application

I have a WPF application and a Silverlight application. They are both used to display a map and share some of the same functionality.
I have created a Silverlight class library project in order to stay DRY. I'm referencing this from both Silverlight and WPF. It contains some utility methods that are useful in both projects. For example, I have this method:
public static void CenterText(TextBlock name, Polygon poly)
The silverlight project has no problem with this. However, I get the following error when calling this from my WPF application:
The type 'System.Windows.Shapes.Polygon' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
However, I have this line at the top of the file:
using System.Windows.Shapes;
so WPF can see the Polygon class perfectly fine.
My guess is that the silverlight class library uses a version of the framework which is not compatible with the version that the WPF project is using.
So the question is, am I stuck rewriting exactly the same code in my WPF application or is there some way I can share between the two?
Thanks!
You are right, Silverlight uses a completely separate version of the framework. It's much, much smaller than event the .NET client runtime.
This means you can't mix WPF and Silverlight assemblies in the same application.
I ran into this error because I had downloaded the Expression Blend SDK for Silverlight instead of what I SHOULD have downloaded: Microsoft Expression Blend Software Development Kit (SDK) for .NET 4. It can be found on MSFT's website, here:
http://www.microsoft.com/en-us/download/details.aspx?id=10801
As soon as I downloaded the Expression Blend SDK for .Net, removed all of the Blend SDK for Silverlight references, and added those same references as Blend for .Net, I was up and running.
In Silverlight the class is in System.Windows.dll while in WPF it is in PresentationFramework.dll the library tries to get a hold of the Silverlight assembly which is not referenced by default in a WPF application.

WPF and ToolboxItem(false)

I'm setting ToolboxItem(false) attribute on couple of classes in my control library to prevent the from being added to Toolbox. This attribute works perfectly well with ASP.NET designer but with WPF designer it seems to have no effect.
Is there some other way to achieve this with WPF or is just unsupported?
Found the answer myself. You should use ToolboxBrowsable(false) attribute from Microsoft.Windows.Design namespace rather than ToolboxItem(false) from System.ComponentModel.

Resources