Xamarin: 'CustomBottomNavAppearance' does not implement interface member 'IShellBottomNavViewAppearanceTracker.SetAppearance[...]' error - c#

I've recently tried to customize the tabbar using a custom ShellRenderer in my app using Xamarin and Visual Studio 2019. I've found this question where someone does exactly what I need and the question has an answer which explains it in great detail.
Now, my problem is that when trying to build the app, I get the following error:
'CustomBottomNavAppearance' does not implement interface member 'IShellBottomNavViewAppearanceTracker.SetAppearance(BottomNavigationView,IShellAppearanceElement)' (Errorcode CS0535, line 32)
Now, the sample project that the user in the other question provides works perfectly on my machine, yet implementing it in my project doesn't work, although they are practiacally identical.
I expect this to be very obvious for an advanced user, so sorry about that, I'm still learning and would like to just implement this feature right now, even if my skills might not allow me to do that.
Thanks in advance for any replies!
This is my 'MyShellRenderer.cs' class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Google.Android.Material.BottomNavigation;
using MyProject;
using MyProject.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(AppShell), typeof(MyShellRenderer))]
namespace MyProject.Droid
{
public class MyShellRenderer : ShellRenderer
{
public MyShellRenderer(Context context) : base(context)
{
}
protected override IShellBottomNavViewAppearanceTracker CreateBottomNavViewAppearanceTracker(ShellItem shellItem)
{
return new CustomBottomNavAppearance();
}
}
public class CustomBottomNavAppearance : IShellBottomNavViewAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(BottomNavigationView bottomView)
{
}
public void SetAppearance(BottomNavigationView bottomView, ShellAppearance appearance)
{
IMenu myMenu = bottomView.Menu;
IMenuItem myItemOne = myMenu.GetItem(0);
if (myItemOne.IsChecked)
{
myItemOne.SetIcon(Resource.Drawable.icon_about);
}
else
{
myItemOne.SetIcon(Resource.Drawable.icon_feed);
}
}
}
}
Edit: I've just found out that the issue actually only exists with the Android version (well, the iOS version at least doesn't throw the error).
Update: I have been able to fix the issue by using "using Google.Android.Material.BottomNavigation;" "using Android.Support.Design.Widget;". My guess it that the old one is now deprecated and only works with the 4.x.x releases, not my 5.x.x release. Thanks everyone!

Per this docs,The error does not implement interface member Errorcode CS0535 means A class must implement all members of interfaces from which it derives or else be declared abstract.So the issue must be that the method SetAppearance has not been correctly implemented.When I Remove or Comment the SetAppearance method, the error appears.
The solution is that using using Google.Android.Material.BottomNavigation instead of using Android.Support.Design.Widget.

Related

How can I match XNA with Windows Form in VS 2019?

I'm trying to create a music player with an audio visualizer starting from a windows game project on VS 2019. To do so I created a custom display, draggable from the toolbox, in order to put it inside a form.
From tutorials I've seen it is necessary to include three classes from GraphicsDevice and I've done it, but when I put them inside the code, the Display class does not inherit and VS does not recognize the keywords.
To be precise WinFormsGraphicsDevice is marked as an error, and its methods as well.
Does anybody have any hints about this?
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsGame2.CustomControls
{
public class Display : WinFormsGraphicsDevice.GraphicsDeviceControl
{
protected override void Initialize()
{
}
protected override void Draw()
{
GraphicsDevice.Clear();
}
}
}

How to disable the back button in android C#

Im making an Android App using Xamarin.Android in Visual Studio and I've been trying to disable the back button in my secondary activity, and the methods I've been using is adding this code into the activity
#Override
public void onBackPressed() {
}
So the code would look like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Java.Lang;
namespace The_Coder_Quiz
{
[Activity(Label = "Activity2")]
public class Activity2 : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.easyQuiz);
// Create your application here
}
#Override
public void onBackPressed()
{
//Include the code here
return;
}
}
}
But that gave me an error which was:
member modifier 'public' must precede the member type and name
Im assuming that is because im doing the project in C#, what would be the correct solution since im doing this in C# and not Java (new to android development)
Im trying to keep off StackOverflow when learning but its kinda hard to find references online for Android Development in C#
The correct way to do an override in C# is:
public override void OnBackPressed()
{
//Include the code here
return;
}
For example if it is a login page (Activity):
public override void OnBackPressed(){
//by this way.. user want be able to hit the back button
// unless user is logged in
if (user.IsLoggedIn()){
base.OnBackPressed();
}
}
Check this:
OnBackPressed in Xamarin Android
And about android development using Xamarin, these are some tutorials:
Xamarin.Android Get Started
JoeRock on Youtube

C# "await" error when using WinRT from Desktop app

I trying to get my GPS position from a Desktop app, using Windows Runtime, in C#.
I followed this how-to to set up Visual Studio and this code sample to create the following trivial code as a C# console app :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime;
using System.Windows;
using Windows;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
namespace GeoLocCS
{
public sealed partial class Program
{
static void Main(string[] args)
{
Test test = new Test();
Console.Read();
}
}
public class Test
{
private Geolocator geolocator;
public Test()
{
Console.WriteLine("test");
geolocator = new Geolocator();
this.getPos();
}
async void getPos()
{
Geoposition pos = await geolocator.GetGeopositionAsync();
Console.WriteLine(pos.Coordinate.Latitude.ToString());
}
}
}
When trying to compile, I get the error :
Error 1 'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Devices.Geolocation.Geoposition>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?
I tried to reference every DLL that I could, like "System.runtime", "System.Runtime.WindowsRuntime", "Windows.Foundation"...
What I am missing ?
Thanks for the answer,
Serge
I finally figured out my problem :
I am on 8.1 so I changed this in the .csproj file (targetingPlatform) instead of targeting 8.0
After that modification, I could reference "Windows"
I manually referenced the two following DLLs :
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.Runtime.dll
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.WindowsRuntime.dll
If you are On Win8.1 Please Use:
<TargetPlatformVersion>8.1</TargetPlatformVersion>
and not 8.0.
Adding to the existing answers:
I suddenly got this problem with a multiproject solution in WPF (still don't know why). I tried switching between TargetPlatformVersions 8.1 and 10.0, tried using the v4.5- and v4.5.1-System.Runtime.WindowsRuntime.dll, always alternating between BadImageFormatException and FileNotFoundException.
Turned out to be references in some of the app.config-files (not the .csproj-files!). Visual Studio 2017 must have added them at some point and as soon as I removed these entries, the above solutions finally worked.

class in C# doesn't recognize Image class from System.Drawing

I was writing my Patient class, for clinic software, and wanted to add a Photo property, but the Image class doesn't seem to be working in my code, don't know why, considering that I have included System.Drawing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace ClinicFiles
{
public partial class Patient : Person
{
public Image Photo { get; set; }
//etc. etc.
}
}
P.S. What site do you find the best guideline to a beautiful Windows Application design? :) Nice and professional user interface, all details taken care of, as fonts, etc etc. :)
Try right-clicking your project References and adding System.Drawing.

C#: Referencing a windows shell interface

I'm pretty new to C#, I'm trying to complete a little side project I've been working on that uses a small amount of C# code to assist the development of a Windows Desktop Gadget. Basically, I'm trying to implement the IDesktopGadget interface so that I can use the RunGadget method.
Here's what I got so far from reading information about similar interfaces:
[ComImport]
[Guid("C1646BC4-F298-4F91-A204-EB2DD1709D1A")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IDesktopGadget
{
uint RunGadget([MarshalAs(UnmanagedType.LPWStr)] string gadgetPath);
}
Unfortunately, I get an error when I try and create an object from it: "Cannot create an instance of the abstract class or interface 'GadgetTask.IDesktopGadget'"
Can someone point me in the right direction and maybe help me understand what I'm doing wrong at the same time?
You actually need an implementation of the DesktopGadget object in order to use the interface. MS provide a standard COM object to do it on Windows 7. You can create an instance by doing something like:
Type t = Type.GetTypeFromCLSID(new Guid("924ccc1b-6562-4c85-8657-d177925222b6"));
IDesktopGadget dg = (IDesktopGadget)Activator.CreateInstance(t);
Thanks for the guidance. For a little more straight forward help, this is what worked for me:
IDesktopGadget.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace GadgetActivator
{
[ComImport]
[Guid("C1646BC4-F298-4F91-A204-EB2DD1709D1A")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IDesktopGadget
{
uint RunGadget([MarshalAs(UnmanagedType.LPWStr)] string gadgetPath);
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GadgetActivator
{
class Program
{
static void Main(string[] args)
{
Type t = Type.GetTypeFromCLSID(new Guid("924ccc1b-6562-4c85-8657-d177925222b6"));
IDesktopGadget dg = (IDesktopGadget)Activator.CreateInstance(t);
dg.RunGadget(#"C:\Program Files\Windows Sidebar\Gadgets\xxxxxxxxx.Gadget");
}
}
}

Categories