Migrate Xamarin Forms Effect to .NET MAUI - c#

For a Xamarin Forms application, I have been using a solution to track touch using code from an example out of Microsoft's Xamarin Forms Sample Project, specifically the Touch Tracking Effect sample.
I took that sample and simplified it down to just directly starting up with the BoxViewDraggingPage.xaml from App.xaml.cs and removing all other XAML files. That compiled and ran fine.
I then created a .NET Maui App with the same BoxViewDraggingPage (and the same TouchActionEventArgs.cs, TouchActionEventHandler.cs, TouchActionType.cs, and TouchEffect.cs) as was in the Xamarin Forms version.
I added the same TouchEffect.cs files that were in the sample for the specific platforms (iOS also has a TouchRecognizer.cs file)
When running it at that point I got the following:
So then I tried following the instructions for Migrating Xamarin.Forms Effects. The explanation for how Xamarin.Forms effects were set up matched perfectly, but it was unclear to me from that page what class the section titled "Effects in .NET MAUI" was replacing since it had a different class name than the previous code snippets earlier in the article. It seemed like it is replacing the FocusEvent class in the shared platform code and then specifies the platform specific code within #if platform sections (#if WINDOWS, #if __ ANDROID __, etc.) and so I am guessing that means the TouchEffect.cs files are no longer needed in the platform specific folders.
I didn't have a chance to find out if that was the case or if it works, because when I try to compile, I get:
I don't find any missing Nuget packages or assemblies when I tried searching. If I click the dot after Platform, I get the following choices, with instructions to use the navigation bar to switch contexts:
But I am already targeting net6.0-windows10.0.19041.0:
so I'm not sure why it says Not Available for that.
So, I am stuck trying to get this to work.
I am looking either for a solution to get the sample code working as it is in the Xamarin.Forms project, but for .NET MAUI (whether that be set up how the sample originally had it or how it is described in the Migrating Xamarin.Forms Effects link) - it could be that I am missing something simple in how to get that Microsoft.Maui.Controls.Compatibility.Platform.UWP piece to compile.
Or, the other possibility is that same link says that .NET MAUI Handlers can also handle this type of scenario. So if someone can show all the pieces that would need to be modified in order to do the same solution but using .NET MAUI Handlers, I am open to that. But it seems that the easiest path, though, should be to get the Effects working in .NET MAUI since everything is already written that way. I am just leaving both options open in looking for a solution.
EDIT:
OK, I figured out why the UWP portion had red squiggles under it. I figured out what "using the navigation bar to switch contexts" in the above screenshot meant. It meant I needed to select the context in the dropdown pictured below:
However, this just moves the squiggles to PlatformEffect and I cannot figure out what to do with the context or anything else to resolve that:

OK, I found out that PlatformEffect now inherits from Microsoft.Maui.Controls.PlatformEffect instead of the separate Platform inheritances shown in the Migrating Xamarin.Forms Effects example. That example is out of date and I didn't realize that and so it was confusing me.

Related

Xamarin iOS native linking failed for grpc.core

I've been attempting to make grpc work (ssl http2) on Xamarin Forms and after some pain I managed to get it to work on Android using Grpc.Core. However I couldn't get iOS to compile. Working through this problem I was trying to get anything grpc related to work on iOS, and eventually found the grpc experimental xamarin demo, HelloworldXamarin. Found here:
https://github.com/grpc/grpc/tree/master/examples/csharp/HelloworldXamarin
I downloaded the solution, but when I try to compile it I get the following errors:
Error Text:
Native linking failed, undefined symbol: operator delete(void*). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
Native linking failed. Please review the build log and the user flags provided to gcc: -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc_csharp_ext -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc_csharp_ext.a -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc.a
linker command failed with exit code 1 (use -v to see invocation)
For the warning regarding not being able to find libgrpc_csharp_ext.a, I verified that the file was there.
There appears to be some issue with native linking, which I am very unfamiliar with. I'm using nearly the latest Visual Studio (well, 16.5.3), a mac build host with latest OS and XCode updated to latest. Didn't make any changes to the files pulled from git. I only just started working with Xamarin iOS this week, so everything should be in a fairly "default" state.
What could be wrong with my setup/system that makes this not work? I understand that this is an experimental feature still, but I can't tell if I've done something stupid or if there's been some change in something (like XCode? or it needing VS 2017?) that makes this no longer work? Is anyone else able to get this example to compile?
I've also tried newer versions of the grpc nuget packages and that only resulted in more errors.
Ultimately I'm trying to get latest Grpc.Core to work in iOS on Xamarin.Forms, though I have very little experience working with iOS. If there are issues with the latest versions of XCode/Visual Studio/Grpc.Core that are causing this, I'm willing to try to work through them, if someone can point me in the right direction.
It is not at all related to your versions or something that you did or didn't do.
First for some theory:
If someone wants to use Objective-C libraries or CocoaPods packages in their Xamarin project, they will need to create a binding library for this. Take it as some sort of a "bridge" between the native implementation and the later exposed C# code that you can use. You can learn more about the binding from the official documentation here and more specifically here.
To sum up the info - after the bindings have been created, you see a .lib or .a file. This is exactly what they have done - exposed some native code into the libgrpc_csharp_ext.a. Unfortunately, there are some bindings that are not correct. This is exactly what you are seeing here - the aftermath of an incorrect binding.
Looking a bit into the project I got to the following conclusions:
There is an open issue from May 2019 about this - https://github.com/grpc/grpc/issues/19172
Unfortunately, the issue is still active and there is no movement there.
I have confirmed that after version 1.21 (incl.) the build is not working. For now, you can downgrade to version 1.20.1 (last known to work). I have successfully built the solution with it. Please review the changelog and release notes for this specific version (if any) so that you know if it will fit your needs.
Basically, you have 2 options:
Downgrade to the last good version in order to use it;
If you want to use the latest version either wait for the issue to be fixed, or fork the repo and help with the fixing.
If you want to see their build script and help fix the issue, you can start from here.
Another useful resource is this video from the official Xamarin channel.

the namespace "system" could not be added to the project

I am working on a C# PCL. The targets include Windows Phone, iOS, and Android (all via Xamarin). Whenever I add a new class, I get a popup starting with "The namespace system could not be added to the project." It then proceeds me to warn me that things might not work. Well, they do work, but the popup is annoying. Can I stop it?
I guess this is a problem with the Framework version of the namespace systemand your project.
Confirm they both match the same framework.
I recommend you take a look over this link, which addresses a similar kind of issue. Usually when the references are not proper, you may get this kind of issue.

Grid is not supported in a Windows Presentation Foundation (WPF) project

I am learning how to create a Class Library (Windows Store apps) and used a UserControl template to add a user control to it.
Then I added a Grid tag to accompanying XAML. However, the tag is underlined with blue squiggles and when I hover over the tag there is
Grid is not supported in a Windows Presentation Foundation (WPF) project
tooltip shows up.
The library seems to build without errors. I've added the library to an application and use the control in its code. The application is also builds just fine. However, when I run the application I get XamlParseException exception.
I am using Visual Studio 2012 RTM. Both the library and the application reference only two standard assemblies (.NET for Windows Store apps and Windows).
What I might done wrong and how should I fix the library?
In my case I switched from Debug to Release, and then back, and the error was gone.
Go to "Build > Configuration Manager..." and Make a new platform for x86 for all your projects.
It doesn't have to be the active one, you can leave that as Any CPU.
Hope it works as for mine...
I've recently had the same error and found the following in the output window:
10>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFX.targets(268,9): error MC6000: Project file must include the .NET Framework assembly 'WindowsBase, PresentationCore, PresentationFramework' in the reference list.
The solution for me was to add the missing references to my project.
For me it helped to set the "Target framework" in application-properties to .NET 4.0
This appears to be a bit of a "catch-all" for a number of XAML resource errors. I've found two causes so far:
Declaring a Resource outside of the appropriate context- e.g. directly in a UserControl tags, not UserControl.Resources.
Forgetting to include the correct namespace for the "unsupported" class. Example in a basic ResourceDictionary, with no sys namespace defined:
<ResourceDictionary>
<sys:string>I'm not supported</sys:string>
</ResourceDictionary>
I was able to solve my similar issue of..
UserControl is not supported in a Windows Presentation Foundation (WPF) project
.. by removing the PresentationFramework reference and re-adding it via nuget.
[Reposting comment as answer]
I was able to complete the steps with no issues, and it appears you were able to as well. Perhaps there was some other inadvertent modification/setting that was made?
This is xaml getting itself confused. I have the error on one project and not on another. Have a look at the top of the xaml before the grid error and see if there are any references to other controls. Try making a modification that will cause and error and rebuilding one of those controls. Then put it back the way it was to get a succesful build and see if this makes the grid error go away. (it did for me)
Much Like Felix D.s answer, I found from the .csproj file a reference was removed.
Obviously replace the 3 with your needed framework, or use the project properties to set the version ( i think that adds this reference )
Evil Dog Pie was step 1 for me, as some other issues came up. There is always a heap of information in the output log
<Reference Include="PresentationFramework">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
This problem is due to the low version of .NET that you have chosen in your project.
To solve the problem, select the Project from the up menu and then select your Project Properties and from the part of Target Framework select higher version of .NET Framework!
I hope your problem is solved.
Yours sincerely

InitializeComponent() broken when refering Sharepoint.dll

Morning!
I am trying to program against sharepoint with Linq, but have a starting problem.
I guess this might be a newbee problem, but i am one so dont shoot me.
I have created a WPF app and did not add any code. I then add a reference to Sharepoint.Client.dll and Sharepoint.Linq.dll. After this is done i get the red squigel line under InitializeComponent() telling me its not existing in the current context.
This is only a problem in WPF not regular old Windows application.
Spec:
Application is .NET 3.5 since sharepoint does not support 4.0.
Application is x64 as sharepoint is x64 only.
Everything else is default.
Any ideas?
Thanks
First of all, could you check if the target framework of your project is actually set to .Net 3.5?
Secondly, make sure that the Build Action for the xaml file (in the Properties window) is set to "Page"
If neither of these options solve your issue, could you please post the root node declaration of your xaml file (i.e. <Window x:Name=....). There might be a problem there.

Expression blend convert example from Silverlight into WPF

Hey! I was looking at a cool layout example in particular the V3FluidLayout.xaml found inside this set of examples : http://gallery.expression.microsoft.com/en-us/DynamicLayoutTrans
Anyhow - this appears to be a silverlight app - it runs within a browser. I am trying to pull the V3FluidLayout example into a WPF app - and struggling.
I "add an existing item" pulling the .xaml file into my project. When it goes to compile it, the following errors are found :
Are these artifacts Silverlight? The following is the xaml code within the V3FluidLayout.xaml file
http://pastebin.com/h9ujUax6
Can anybody help me pin why this is not working - and how I can convert that xaml code to work inside my wpf app.
Thanks
Andy
Basically (and from only a quick glance), you'll need a reference to the WPF versions of System.Windows.Interactivity and Microsoft.Expression.Interactions - they are part of Blend. Actually look at the references of that project and find the exact same references, only for WPF.
It looks like they contain pretty much the same classes for both WPF and Silverlight, so I think it should work in the end.
Add references to the interactivity assemblies found here:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend.NETFramework\v4.0\Libraries
You need to install the Blend SDK to get them, the come with Blend also.

Categories