Implement missing platform for MvvmCross plugin - c#

I want to use an MvvmCross plugin in my project, however one of my platforms is Wpf.
Unfortunately there's no Wpf implementation (https://github.com/brianchance/MvvmCross-UserInteraction).
What is the proper way of adding WPF platform implementation to my project?
More specifically, my questions are:
In the implementation I need to use UI controls and components to display message boxes, thus should it be "WPF Custom Control Library" or can I use just standard "Class library"?
Do I have to add Nuget packages Mvvm.CrossCore and Mvvm UserInteractionPlugin to my WPF implementation library?
Ideally I'd like to create and test WPF implementation in my own project and then contribute it to plugin repo on github.

The simplest would be to clone the original repo. Then add a new Class Library project for your WPF implementation.
If you look at the existing Windows Store project, it simply adds a project reference to the UserInteraction (PCL) project.
Create a UserInteraction class that implements IUserInteraction. Add your WPF implementation there.
Include the Plugin class so it will auto-register in MvvmCross.
You can then modify the existing .nuspec file to add entries for your WPF assemblies.
This is pretty much how all MvvmCross plugins work.

Related

Building wpf application as type of wpf class libarary

My need is to develop an addin for an application
but WPF application is not allowing to build it in type of WPF Class Libarary
Refering to this question i found that without XAML pages only we can build WPF application in Class Library Type. It it true? Or am I missing something?
I need to add a WPF window to my addin, but they are referring to remove all the windows and add usercontrol? Whats the workaround for it? Or am i doing anything wrong?
What i did now is I just deleted my application.xaml window from my solution and changed the target type to WPF class Libarary and builded the solution and it builded successfully. Is it correct way..? or any other ways there..? Am really new to this WPF !
There two additional templates to build WPF dll's such as WpfCustomControlLibrary and WpfControlLibrary. You will then be able to add a Window (and other WPF-specific elements). And it can certainly contain general-purpose classes. And it will be built into an assembly no different from that from general class library project.
How to: Create a WPF UserControl Library Project
How to add a WPF control library template to Visual C# Express 2008
If you want just create class libary, please, just select Class Library
How to: Create Class Library.
Also, you can add Window to general class library project. Visual Studio just does not expose Window from add new items dialog. A workaround is to add a User Control Item, and then change it to derive from Window.
Yes, you can go on creating a Class Library, adding a XAML view there. In your exe project you will include a reference to that lib and its public XAML windows or user controls should be available under the library's namespace, like any C# class.
Edit
A simple example from GitHub: as you can see, the library project is compiled with a reference to the System.Xaml assembly.
Edit 2
To build an already existing Windows Application project into a Class Library one, besides changing the Output type you have to delete only the App.xaml

C# WPF Library creating

I have a WPF project. I want to use this project in other new projects using a .DLL file, Like MessageBox form in C#, when we use MessageBox.Show to create a form.
Library project file cannot specify ApplicationDefinition element.
When i change the output of the project to "Class Library", the "InitializeComponent();" method makes an error, so does many other methods in the constructor of my window, saying
The name 'InitializeComponent' does not exist in the current context
How do i solve this? and how do i use my library once created?
You can't simply port it to a Class Library. You can hack at the app.xaml and so forth, but it would be best if you create a new "WPF User Control Library" or "WPF Custom Control Library". Migrate over your existing code to it. Make sure to expose Public classes and methods that you wish to call from outside of the library.
You can create a Solution to contain your new library as well as a test WPF Application. That way you can add a reference in the application pointing to your library project. Testing would be easier that way.
As far as how to use the library -- you'll need to do some research on that. There are a number of ways to go about it depending on your needs.
OK, the problem is that you project is an app, not a library. Just changing it to library in settings wont help.
The best this to do is to create a new project of type 'user control library', and then copy all of your xaml and classes over to the new project
Deleting App.xaml from my project worked.

How to structure Xamarin library containing iOS & Android bindings?

I'd like to create a library, which can be used within Xamarin projects.
I also want to reuse iOS as well as Android libraries (static lib & jar). Therefore I created a solution which contains an Android binding project as well as an iOS binding project.
To expose this functionality I'd like to create a single wrapper class (within a shared project), which forwards the call to the appropriate native lib. I first thought that this could be done with the use of if-makros. Unfortunately, it seems like I can't add references to a shared project, which means I am not able to call the binded methods.
Could you expose an interface in your shared library that each platform implements with their specific binding implementation and reference everything through that?

how do you add an ios framework to your C# Xamarin iOS project?

In iOS, you can add frameworks when you go to "Your Project" =>"Targets" => "Build Phases" and then press the add button to add frameworks.
So, lets say I wanted to add CoreVideo framework, CoreMedia framework, and CoreGraphics.framework. How can I add these frameworks to my Xamarin iOS project?
I am new to Xamarin iOS. thanks for reading, I appreciate any comments or suggestions.
In most cases this is done automagically for you.
E.g. when you use a type from MonoTouch.CoreGraphics, like CGColor, then the tooling will add a reference to the CoreGraphics framework. No further action is required from you.
The only time when you need to manually specify frameworks is when you link with a native library that has dependencies on some framework(s) that your application itself might now have.
In general, when you create bindings to an Objective-C library, you add such requirements inside the [LinkWith] attribute. E.g.
[assembly: LinkWith ("libX.a", LinkTarget.Simulator, Frameworks="CoreGraphics")]
You can add several frameworks by separating them with a space.
You can also use the Additional mtouch arguments (from your Project Options) to specify options to the native linker if you do not use a binding project, e.g.
-gcc_flags="-framework CoreGraphics"

Including xib(s) / nib(s) in a MonoTouch Binding project

I'm trying to create a re-useable MonoTouch library that contains Views defined in a xib, and Controller code written in Objective-C.
I have created a static Objective-C library that contains the relevant controller code with all the outlets declared.
A static *.a library obviously can't contain xib/nib data (if this is possible can someone please let me know), so I can't embed the xibs/nibs in this library.
I have created a 'MonoTouch Binding Project' that defines the relevant wrapper classes.
This is where I would ideally also embed the xibs/nibs, and have them included in the app bundle of any final project that links this dll.
Now looking at what a 'MonoTouch Library Project' does with xibs - it compiles it to a nib using ibtool, and then embeds it as a resource in the resultant library dll using the /res option of smcs. I'm assuming this is triggered because the xib file is marked with a "InterfaceDefinition" build action in the project.
However a 'MonoTouch Binding Project' has no "InterfaceDefinition" build action. Is this possible at all using a MonoTouch Binding Project?
I haven't tried it yet, but I'm assuming I could get it working manually by combining what the Library project does with ibtool and smcs /res and what the Binding Project does with btouch and smcs. But I'd rather avoid this, I'm enjoying the lack of Makefiles lately.
Xamarin/MonoTouch team - any plans to add this to Binding Projects in the future? Any way to force it to work currently?

Categories