Using windows forms alongside wpf - c#

Me and a friend are working on a relatively big project, which is basically a darts scoreboard and tournament scheme software with stats tracking etc. The problem is that the tournament scheme part has been done in Windows forms, and that is a very massive part of the project, but the scoreboard part has to be done in WPF because that UI needs a little style tweaking. The thing is how do I go about getting these 2 working in conjunction, starting the whole thing from... well the WinForms end, and it exchanging data with the Scoreboard(WPF app) I need very basic things, like passing a string from a label in the form to somewhere in the WPF window. I would move the tournaments scheme to WPF, but we just don't have enough time at this point.

You can use controls created in WPF application in your Windows Forms application, for an example see Walkthrough: Hosting a WPF Composite Control in Windows Forms.
Or you can use control created in Windows Forms application in your WPF application, example:
<WindowsFormsHost>
<wf:MaskedTextBox x:Name="mtbDate" Mask="00/00/0000"/>
</WindowsFormsHost>

Related

Enable Back/Forward & Refresh Gestures in Universal Windows App (XAML)

I'm building a set of small internal apps for our business. A majority are web based tools. To provide easy access to all of the tools to all our staff. Previously I built small windows applications which are used currently. However, I'm looking to upgrade these to Universal Apps as we can better distribute future applications through our Microsoft Business Store.
Currently when placing a WebView into the UWP app, the app loads and functions as expected in terms of loading the WebView. However I cannot seem to find a means to implement Back / Forward navigation (previously this was a toggled option in the properties group) if a user navigates using Back/Forward on their mouse etc. Any pointers would be greatly appreciated. No doubt it's something quite obvious I haven't spotted.
I was expecting the basic back / forward navigation to work out of the box (as is the case I have experienced previously when developing for other platforms)
The app I'm currently working on is using the UWP with XAML and C# and currently has the WebViews implemented using:
<WebView x:Name="webView" Source="https://app.domain.com"/>
within MainPage.xaml and no further modifications made to this app as it stands.
I regularly use SO as a guest to find answers to questions but I couldn't see a direct answer to this scenario.
Thanks
The WebView class has built-in APIs that could Go Back/Forward. You could add some buttons and call them in the click event.

Implementing of MediaPlayer and MediaTimeline in Windows Forms [duplicate]

Can both WPF and Windows forms controls be used within one application? How difficult or practical an idea is this?
It is fairly straightforward to host WPF controls in a WinForms app with an ElementHost adapter or WinForms controls in a WPF app with a WindowsFormsHost adapter. There are not too many resources on the web showing how to do either of these, however. In the process of learning how to do this for myself I quickly discovered the inherent symmetries between the two pathways. I distilled all my notes into an article comparing and contrasting these symmetries using a unique approach: the article is really two side-by-side articles, comparing every step in detail, starting from creating a user control in one technology to hosting it in an application in the "opposite" technology. My article, published on SimpleTalk.com in August 2010 is available here: Mixing WPF and WinForms.
For completeness, here are a couple good MSDN references, one for each pathway. In fact, the demo solution accompanying my article started from both of these:
Hosting a Windows Forms Composite Control in WPF
Hosting a WPF Control in Windows Forms
I believe there is a WindowsFormsHost control you can put in your WPF apps which will do interop back to WinForms code:
http://blogs.msdn.com/ivo_manolov/archive/2007/07/26/wpf-win32-interop-part-1-hosting-winforms-controls-in-wpf-windows.aspx
We hosted significantly complex WPF controls in an existing LOB WinForms app. It can be done, but we did have issues (some no doubt caused by the steep learning curve). These primarily had to do with loss-of-focus events not being fired when expected, and also keyboard navigation issues.
You can also use an HWNDSource and HWNDHost controls to embed WPF controls in a WinForms (or any Win32, really) app.
When hosting non-WPF content (Be it HTML, WinForms, or Win32 content), you will haveAirspace issues. This means you can't completely compost the WPF content with the hosted content. You also can't animate it etc. There are some interesting issues with respect to scrollviewers see here for more details and a fix also.
Yes you can, both Windows Forms within a WPF application, and WPF controls within Windows Forms. www.novamind.com's mind-mapping application is a successful mix of the two technologies.

Expression Animation in WPF

Is there any kind of animation available for WPF app like expression animation in UWP?
Suppose I want to move a rectangle vertically with my mouse and another rectangle should move horizontally accordingly to the first one.
You can try with WindowsXAMLHost: it's a new feature, still in development, incorporated in the Windows Community Toolkit.
By using the WindowsXamlHost control, you can add built-in or custom UWP controls to the User Interface (UI) of your WPF or Windows Forms desktop application, even with custom functionalities.
Check the related MSFT Docs here: UWP controls in Desktop applications
Then get the companion app from the Win Store: Windows Community Toolkit Sample app
It will be a little bit tricky... but I'm sure that it is possible to do what you requested.
Best regards

How to open keyboard if the device is in 'Tablet Mode'

When clicking on a text field, automatically open up the Windows 10 touch keyboard if the device is in 'Tablet Mode'.
How to Know device is in 'Tablet Mode'?
How to open keyboard in WPF?
I think this is a misunderstanding. WPF doesn't run in tablet mode at all and doesn't have an on-screen keyboard. It's strictly a desktop-oriented technology. I'm assuming that you are building an applicant in XAML and that you want the same application to run in both places without having to create to separate projects.
WPF is a technology to run XAML in desktop mode whereas a different technology, called WinRT, is required to run applications created in XAML in tablet mode on Windows 10.
If you want to build a single application that is capable of running in both modes, you need to consider adopting an MVVM "framework" to help you out with this task.
The purpose of using MVVM in this context is that it enables you to separate your cross-platform "business logic code" inside classes called "ViewModels" while putting your UI specific code inside a XAML file with a different XAML file being created for each platform you are supporting (for example WPF, Silverlight, Windows Phone, WinRT).
Here are some MVVM frameworks that can help you with this:
Caliburn.Micro:
(http://caliburnmicro.com/documentation/windows-runtime)
MvvmCross: https://mvvmcross.com/
Catel: (https://catel.codeplex.com/)
Simple MVVM: (https://simplemvvmtoolkit.codeplex.com/)
MVVMLight: (http://www.mvvmlight.net/)

Using Windows Store controls in a Windows Forms application

We are looking at creating a new mobile application which will run on tablets using full Windows 8. We would like to be able to use full SQL for our data storage (which can be accessed easily using Windows Forms apps), but also retain the nice controls and touch friendliness provided by Windows Store apps (e.g. the LayoutAwarePage and the Windows 8 XAML controls).
We were looking at a way to use the Windows Store libraries within a Windows Forms application (as mentioned here: http://msdn.microsoft.com/en-us/library/windows/apps/jj856306.aspx#consuming_standard_windows_runtime_types), but have had no joy beyond adding the reference to a solution.
Does anyone know how to add a LayoutAwarePage to a Windows Forms application? Or is there a better way to approach this?
If you want it to look like a windows 8 app try having a look at MahApps
http://mahapps.com/MahApps.Metro/
Its pretty easy to use and look pretty good, this is for wpf though not winforms

Categories