Why is the Surface Toolkit demanding an Application? - wpf

I'm trying to use Surface Toolkit controls on WPF controls in a WPF Control Library. I'm using these controls in a MFC front using HwndSource. All of that is fine. The problem I have is that now I get the following exception:
A System.Windows.Application is required. Please initialize an Application before using this API.
at Microsoft.Surface.Presentation.SurfaceMetrics..ctor()
at Microsoft.Surface.Presentation.SurfaceMetrics.get_Instance()
at Microsoft.Surface.Presentation.DefaultColorSource..ctor(Int32 rank)
at Microsoft.Surface.Presentation.SurfaceColors..ctor()
at Microsoft.Surface.Presentation.SurfaceColors.EnsureInstance()
at Microsoft.Surface.Presentation.SurfaceColors.get_ControlForegroundBrushKey()

The solution was to new up an instance of System.Windows.Application in my MFC application. That pacified the Surface Toolkit.
See the answer here for my complete WPF in MFC solution. It's pretty marvelous, I have to say. Way better than it was in the old days.

Related

Does the new SvgImageSource class designed for UWP can be used in WPF project

It seems that a relatively new class: SvgImageSource can only be used in UWP. Is there any way to use it in a WPF project and how?
Please take a look at this framework:
SharpVectors
The other way is to convert your SVG files to XAML path geometry and using them easily.
It will be possible to use any UWP XAML UI in WPF using XAML Islands. This is currently available as a preview using the WindowsXamlHost control which is part of the Windows Community Toolkit. Also note, that when using UWP controls in WPF apps, the app will then work only on Windows 10 client PCs.

Host WPF Application(Caliburn Framework) Inside Winforms

We have an existing Legacy Winforms application which is old and hard to maintain. So we decided to re-write the application using WPF. Due to lack of resource, we plan to have a hybrid type, where new features will be developed in WPF and over the course of time will migrate everything from Winforms to WPF.
Now the problem is, how can we integrate WPF application that uses MVVM framework to be launched from Winforms application. I tried "ElementHost" control to host WPF application. But I dont know how to achieve it with MVVM framework. Tried with Caliburn.Micro and getting an null exception when the BootStrapperBase.Initialize() method is called.
Please advice.
After reading the Caliburn documentation see here, there is an option where we can pass “false” to the base constructor’s “useApplication” parameter.
This worked for me.
This launches the application. I tried playing around passing a reference to the WPF applicaton which contains event and method.

WPF - Windows Forms Interoperation

I am abit confused about interoperations between forms. I have an c#.Net application developed using DevExforms. On the other hand I have a XNA application which I want to use it as 3d GUI. But it is diffucult to interact between them. Of course it is not useful, it is ugly too.
So I see a way to develop 3d model viewer app using WPF but WPF controls and windows forms controls needs .Net Framework 4.5 to interact betwwen. But I must use VS2010.
So I am confused. What must I do. How can I easily develop a 3d app with Windows Forms or how can i interact any platform with my app. Actualy if you were me what will you do?
WPF controls and WinForms controls don't need .Net framework 4.5 to work together. the interoperability exists before (4.5). take a look in MSDN

WPF forms+ Winforms in MDI

We have an application which is using winforms. Now we want to upgrade it.
We are planning to use some WPF forms and some old winforms. and we also need to use MDI.
From MDIParent we need to open both winforms and WPF forms. And these forms need to be in tile format. I got to know that WPF doesn't support MDI.
Is there any other way to achieve this?
Using AvalonDock, can we display the forms in tiles format also. I know that it display in Dockable format.
why you want to upgrade your application to wpf and still use some of your old winforms and the mdi concept any further?(i dont like mixup both:))
for quick and dirty what about using your winform app and integrate wpf in it - if you want/have to?
EDIT:
if you want your WinForms in Wpf you can use
<WindowsFormsHost />
It should work with Avalon too. Here is an example for WindowsFormsHost.

Creating graphics control in WPF and integrate to other winform application

We have a existing applicaiton in winform .net. It has a form which displays a kind of flow chart diagram. Now we want to create a control which has enhanced graphics to display this flow chart. With my limited knowledge on wpf, is it possible -
Create a graphics control in wpf which is display the flow chart
Integrate this control to exisiting winform application.
The diagram should have user interation, like moving blocks in the chart.
Is wpf a better solution ?
Thanks.
it is possible to integrate WPF into Winform tutorial here.
With regards to actually creating a flow chart and making it interact with your existing Winform can have its own challenges. Keep in mind that WPF is a very powerful tool so you should consider moving over to WPF if you have the man-power and resources to do so.
Also look into the Model-View-ViewModel design pattern for WPF and you cannot go wrong. Good luck.

Resources