I need to override the draw method, but I get the error message:
Draw(System.Drawing.PointF)' is marked as an override but no suitable method found to override (CS0115).
This is what I do: I create a new project, add an empty class and try to override.
Here's the code:
using System;
using UIKit;
using System.Drawing;
using CoreGraphics;
using CoreImage;
using Foundation;
using CoreAnimation;
namespace Test
{
public class Tester : UIView
{
CGPath path;
public override void Draw (PointF rect){
base.Draw ();
}
public Tester ()
{
path = new CGPath ();
}
}
}
Actually I'm trying the Xamarin's tutorial.
http://developer.xamarin.com/guides/ios/application_fundamentals/graphics_animation_walkthrough/
The problem is that you create a program with the Unified API (see "using CoreImage" at the top). In Unified API, we no longer use PointF, SizeF or RectangleF, as those are 32-bit structures, so they do not work on 32/64 bit modes.
In Unified, you need to use "CGRect" instead of "RectangleF"
So to fix your program, all you have to do is replace "RectangleF" with "CGRect"
The tutorials currently reflect the Classic API, and once we officially release the final version of Unified, they will be switched over.
You can't override different methods. The original method has no arguments. If you want to override the Draw method, you need to delete your Draw function arguments.
Related
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.
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();
}
}
}
I have qr page in xamarin forms, and what i want is when the qr is shows up the screen brightness will be brighter, and i cant find solutions for that. i found some code in internet but it return with some error code message
EDITED :
I deleted the source code because its look like make some people confused, the code that i tried is for xamarin android and thats why it didnt work for me (I thought the xamarin.android and xamarin.forms code is almost same thats why i copy the code and paste it in xamarin forms and got some error message). And now my Real question is How to Change the screen brightness via xamarin Forms can we do that ? if yes how any link that can i try thanks
Xamarin.Forms is not a platform abstraction, but a UI abstraction. Hence there is no access to system services like the screen brightness. Neither did I find a NuGet to achieve this, hence you'll have to implement platform specific classes to adjust the screen brightness and resolve via DependencyService.
Implement the interface in your PCL
public interface IBrightnessService
{
void SetBrightness(float factor);
}
and use that interface operations using DependencyService from your common project to your platform specific implementation
var brightnessService = DependencyService.Get<IBrightnessService>();
brightnessService.SetBrightness(.2);
For a very good compact example of how to use DependencyService see this page
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
Android
Your error message
An Object is required for the non static field, method , or property 'Windows.Attribute'
means that you are trying to access a type as if it was an object. You need a context in which there is a Window:Window object, this would be the case in your MainActivity for instance.
When you are in another context you'll need to obtain an instance of Window somehow. Pre 2.5 this was possible with
var window = ((Activity)Forms.Context).Window;
This still works, but is deprecated. Anyway, you could use the CurrentActivity plugin and get the Window with
var window = CrossCurrentActivity.Current.Activity.Window;
(source)
using Xamarin.Forms;
[assembly: Dependency(typeof (AndroidBrightnessService))]
public class AndroidBrightnessService : IBrightnessService
{
public void SetBrightness(float brightness)
{
var window = CrossCurrentActivity.Current.Activity.Window;
var attributesWindow = new WindowManagerLayoutParams();
attributesWindow.CopyFrom (window.Attributes);
attributesWindow.ScreenBrightness = brightness;
window.Attributes = attributesWindow;
}
}
iOS
Use UIScreen.MainScreen.Brightness to adjust the brightness.
using Xamarin.Forms;
using UIKit;
[assembly: Dependency(typeof (iOSBrightnessService))]
public class iOSBrightnessService : IBrightnessService
{
public void SetBrightness(float brightness)
{
UIScreen.MainScreen.Brightness = brightness;
}
}
Android:
public void SetBrightness(float brightness)
{
Window window = (MainActivity.Instance as Activity).Window;
var attributesWindow = new WindowManagerLayoutParams();
attributesWindow.CopyFrom(window.Attributes);
attributesWindow.ScreenBrightness = brightness;
window.Attributes = attributesWindow;
}
I added to the reference the OpenHardwareMonitorLib.dll
Now I added in my code: using OpenHardwareMonitor.Hardware;.
Then I did in the top form level: Isensor Sensor;
But I can't "new" it i cant create an instance of it and I'm getting null exception on it in the constructor:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using OpenHardwareMonitor.Hardware;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
ISensor Sensor;
public Form1()
{
InitializeComponent();
string t = Sensor.Name;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Cannot create an instance of the abstract class or interface 'OpenHardwareMonitor.Hardware
I tried ot look in the source code in the code.google.com site: http://code.google.com/p/open-hardware-monitor/source/browse/#svn%2Ftags%2F0.3.2%2FWMI
But i dont want to use all this code. I downloaded the program Open Hardware Monitor and except the exe file there is a dll file im using now in my project i was sure i can use the dll to use it easier. All i want for now is to get the temperature of the video card gpu.
First, you can't new interfaces. You can only new concrete classes.
Second, I recommend renaming your variable from Sensor to sensor, or _sensor, or something along these lines. There is a Sensor class. It's best to avoid confusion.
What I did was downloaded the DLL and opened it up in ILSpy. Let's see what classes implement this interface. I urge you to download ILSpy and try this out for yourself.
Here's the resulting ILSpy window. Now in the bottom right I had done an "Analyze" on the interface to see where it is exposed. There don't appear to be any factory methods that return an ISensor.
Back over on the left side, we see that one class implements ISensor: the Sensor class. This class has four constructors. These will come up in intellisense in Visual Studio, or if you navigate to the Sensor class in ILSpy you can see the constructors.
What you'll end up needing to do is sensor = new Sensor(...); As for which constructor you use... that's up to you.
So i have simple application, just a few lines:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectInput;
namespace asdasd
{
public partial class Form1 : Form
{
public Device joystick;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (
DeviceInstance di in
Manager.GetDevices(
DeviceClass.GameControl,
EnumDevicesFlags.AttachedOnly))
{
joystick = new Device(di.InstanceGuid);
break;
}
if (joystick == null)
{
throw new Exception("No joystick found.");
}
}
}
}
and i try to get the active joystick on my computer, but i get error:
i have the assembly Microsoft.DirectX.DirectInput and i have directX SDK 2010 installed.
Can someone tell me where is the problem?
Try adding this to the config file:
http://devonenote.com/2010/08/mixed-mode-assembly-error-after-upgrading-to-dotnet-4-0/
(if configuration already exists, just merge these in)
And, maybe it's not the right place, but just take a look at XNA... Things are usually much easier with that.
I couldn't paste the XML directly here, it doesn't show up.
The DirectX assemblies are built against .NET v1.1 Microsoft stopped actively developing them before .NET v2.0 was released.
They cannot be used in projects targeting other than .NET v1.1. XNA is the "blessed" path forward for managed access to Direct X features. I don't know all if it's features, but SlimDX appears to give a more Direct X feeling API for C# than XNA, though I have not used it, I've heard a lot about it.
You might find better responses for chosing an upgrade path over at gamedev.stackexchange.com though.