create a cocossharp project in xamarin - c#

Im new in xamarin studio and im trying to create a cocosproject following the official guide, but this document is not very clear and my project have so many errors.
https://developer.xamarin.com/guides/xamarin-forms/advanced/cocossharp/#nuget
I've created a xamarin.form with IOS, android and PCL as guide say
I've added the cocosSharp packages to IOS and Android projects
BUT
if i don't add the cocosSharp package to PCL target, the cocos Classes cant be found by the code
And if I try to add the cocosSharp packages to PCL, console show this
Could not install package 'CocosSharp 1.7.1'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
i tried to change the targetFramework but this don't help me
if someone work with cocosSharp and xamarin studio V6, please how can i solve this ?
Or how can i add the add in of cocosSharp in Galery like in previous versions of xamarin ?
This is the code in a ContentPage, Cocos Classes can't be found
public class MyPage : ContentPage
{
public MyPage()
{
Content = new StackLayout
{
Children = {
new Label { Text = "Hello ContentPage" }
}
};
}
void CreateTopHalf(Grid grid)
{
// This hosts our game view.
var gameView = new CocosSharpView()
{
// Notice it has the same properties as other XamarinForms Views
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
// This gets called after CocosSharp starts up:
ViewCreated = HandleViewCreated
};
// We'll add it to the top half (row 0)
grid.Children.Add(gameView, 0, 0);
}
void HandleViewCreated(object sender, EventArgs e)
{
var gameView = sender as CCGameView;
if (gameView != null)
{
// This sets the game "world" resolution to 100x100:
gameView.DesignResolution = new CCSizeI(100, 100);
// GameScene is the root of the CocosSharp rendering hierarchy:
gameScene = new GameScene(gameView);
// Starts CocosSharp:
gameView.RunWithScene(gameScene);
}
}
}

just figured this out myself. It's true that there's no matching build for Profile 259. Try 151 instead:
Right click the PCL project in your solution explorer
Click 'Options'
Click 'General' on the left hand side.
Change the Current Profile to "PCL 4.6 - Profile151"
Click 'OK'.
Now you'll need to refresh the Nuget Packages so that Xamarin Forms can redownload the right profile. Afterward you can successfully add CocosSharp.Forms.

Related

CefSharp old version issue gives notice of upgrade your browser on every website

i have created a chromium following online tutorials
using CefSharp;
using CefSharp.Internals;
using CefSharp.WinForms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public CefSharp.WinForms.ChromiumWebBrowser browser;
private void label1_Click(object sender, EventArgs e)
{
MessageBox.Show(Cef.ChromiumVersion);
browser = new CefSharp.WinForms.ChromiumWebBrowser("google.com")
{
Dock = DockStyle.Fill,
Size = new Size(600, 600),
Location = new Point(200, 200),
};
this.panel1.Controls.Add(browser);
}
}
Every thing is working fine but it shows version
43.0.2357.130
when ever i go to any website it show update notice like google.com trello.com etc etc
Please Guide me how to upgrade latest version of my custom browser
You need to upgrade you visual studio to 2019
you need to install NuGet Package Manger and search for cefsharp it auto installs every thing

Xamarin Forms and xam.plugin.media: could not resolve reference to Xamarin.Essentials.Permissions

I am following a tutorial on how to browse images on the phone with Xamarin Forms.
In the MainPage.xaml I have:
<Button Text="Select a picture"
Clicked="SelectImageButton_Clicked"/>
<Image x:Name="selectedImage"/>
</StackLayout>
In the MainPage.xaml.cs, is the following code for the Click event handler:
private async void SelectImageButton_Clicked(object sender, EventArgs e)
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsPickPhotoSupported)
{
await DisplayAlert("Error", "This is not supported on your device", "OK");
return;
}
var mediaOptions = new PickMediaOptions()
{
PhotoSize = PhotoSize.Medium
};
var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions);
if (selectedImageFile == null)
{
await DisplayAlert("Error", "The picture is null", "OK");
return;
}
selectedImage.Source = ImageSource.FromStream(() => selectedImageFile.GetStream());
}
Building the solution works, but as soon as I press the button in the emulator, I get an error.
So, I have set the linker (Droid Properties > Android Options > Linking) to Sdk Assemblies Only.
Then i get the following error when trying to build the solution:
Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'Xamarin.Essentials.Permissions/BasePlatformPermission' (defined in assembly 'Plugin.Media, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded.
I have created a new project, updated the Xamarin.Forms NuGet Package to version 4.6.0.726,
updated the Xamarin.Essentials version to 1.5.3.1 and then installed the xam.plugin.media package, version 5.0.1
When trying to find similar issues with solutions, I found that there might be a reference to Essentials that is not pointing to the correct version and that I should change that in the Android project within the solution. However, since I am pretty new to Xamarin and Android development, I would not know where to find these references.
Am I on the right track towards a solution, and if yes: what steps do I need to take to resolve this?
If (!rightTrack)
{
return solution;
}
Many thanks in advance for your input!
When I test your code with the same version of Xamarin.Forms, Xamarin.Essentials, xam.plugin.media, I reproduce the error BasePlatformPermission.
You could use the older version 4.0.1.5 of xam.plugin.media. The error would fix.

Reference to the right "System" in c# project

I am new to c# and visual studio and have run into some trouble.
I have created a project with references to "Windows" and ".Net" in visual studio because I want to test a little with smart cards.
The code:
using System;
using Windows.Devices.Enumeration;
using Windows.Devices.SmartCards;
class HandleSmartCard
{
public async void checkNumberOfSmartCards()
{
string selector = SmartCardReader.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
// return "2";
}
}
So far it looks fine. However I also want the project to be able to use
System.Windows.Forms; which I have used in a previos test.
I add reference to System.Windows.Forms; and try to create a form. However in that form when I try this:
Form prompt = new Form();
System.Windows.Forms.Button confirmation = new System.Windows.Forms.Button() { Dock = DockStyle.Bottom };
confirmation.Click += (sender, e) => { prompt.Close(); };
I get a red line under "Close" with the message:
Reference to type component claims it is defined in system but could
not be found.
System is referenced at top of file, but I am guessing it is the wrong type of system right?
Can I somehow use "both Systems" in one project so to speak?
I hope someone understands what I mean and can help me understand this.
You're most likely working on a UWP app. The API for UWP apps is a very small subset of the full .NET framework. You can find more information here
https://msdn.microsoft.com/en-us/library/windows/apps/mt185501.aspx
You're attempting to reference System.Windows.Forms which is not allowed in UWP applications.
Looks like you're trying to create a popup to ask the user something. For this, use the MessageDialog class.
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.messagedialog.aspx

Windows.UI.Notifications is missing

I want to create simple toast notification to action center in windows 10 from this example. But I got problem on Step 2:
using Windows.UI.Notifications;
It`s missing. But I have spent a lot of time to find it and got no result. I really have no idea where I can find or at least download it.
What I tried:
After long search I found Windows.UI.dll in C:\Windows\System32 but when I try to add it as reference into project I got this error. Even after I tried to copy it and made this fully accessible nothing changed
I tried to reinstall .Net (I`m using 4.5.2)
Installed Windows 10 SDK
Tried to import with global
Added
<PropertyGroup>
<TargetPlatformVersion>10.0</TargetPlatformVersion>
</PropertyGroup>
Added System.Runtime.dll reference
Example code which probably is useless for you:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.QueryStringDotNET;
using Windows.UI.Notifications;
namespace MessagerClient.Notifications {
class DefaultWindowsNotification {
public static void notificationTest() {
string title = "Andrew sent you a picture";
string content = "Check this out, Happy Canyon in Utah!";
string image = "http://blogs.msdn.com/something.jpg";
string logo = "ms-appdata:///local/Andrew.jpg";
ToastVisual visual = new ToastVisual() {
BindingGeneric = new ToastBindingGeneric() {
Children =
{
new AdaptiveText()
{
Text = title
},
new AdaptiveText()
{
Text = content
},
new AdaptiveImage()
{
Source = image
}
},
AppLogoOverride = new ToastGenericAppLogo() {
Source = logo,
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
};
Console.WriteLine("NOTIFICATION");
//Can`t use because of Windows.UI library
ToastNotificationManager.CreateToastNotifier().Show(visual);
}
}
}
You have to fight Visual Studio pretty hard to use these UWP contracts in a Winforms app. You got off on the wrong foot right away with the wrong TargetPlatformVersion, pretty hard to recover from that. Full steps to take:
Edit the .csproj file with a text editor, Notepad will do. Insert this:
<PropertyGroup>
<TargetPlatformVersion>10.0.10586</TargetPlatformVersion>
</PropertyGroup>
Which assumes you have the 10586 SDK version installed on your machine. Current right now, these versions change quickly. Double-check by looking in the C:\Program Files (x86)\Windows Kits\10\Include with Explorer, you see the installed versions listed in that directory.
Open the Winforms project, use Project > Add Reference > Windows tab > tick the Windows.Data and the Windows.UI contract. Add Reference again and use the Browse tab to select System.Runtime. I picked the one in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\ .NETFramework\v4.6.1\Facades. This reference displays with a warning icon, not sure what it is trying to say but it doesn't appear to have any side-effects.
Test it by dropping a button on the form, double-click to add the Click event handler. The most basic code:
using Windows.UI.Notifications;
...
private void button1_Click(object sender, EventArgs e) {
var xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
var text = xml.GetElementsByTagName("text");
text[0].AppendChild(xml.CreateTextNode("Hello world"));
var toast = new ToastNotification(xml);
ToastNotificationManager.CreateToastNotifier("anythinggoeshere").Show(toast);
}
Embellish by using a different ToastTemplateType to add an image or more lines of text. Do keep in mind that your program can only work on a Win10 machine.
If anyone should happen to stumble on this, see this similar but newer post -
Toast Notifications in Win Forms .NET 4.5
Read Stepan Hakobyan's comment at the bottom.
Essentially, I'm seeing the same thing. This code runs, I can step through it line by line with no exceptions but the toast notification is never shown within a Form app.

OxyPlot.Xamarin.Forms package breaks Resource.Designer.cs?

I'm trying to use the OxyPlot.Xamarin.Forms package in my shared Xamarin.Forms project. I added the OxyPlot packages with the NuGet package manager in both the portable and the platform specific (Android) projects like descriped at:
http://docs.oxyplot.org/en/latest/getting-started/hello-xamarin-forms.html
Then I initialized the OxyPlot renderers in the Android project. Now, when I try to start the App the Resource.Designer.cs file is generated, but I get hundreds of errors like so:
Error CS0117 'Resource.Attribute' does not contain a definition for 'mediaRouteSettingsDrawable' OxyPlotShared.Droid \OxyPlotShared\OxyPlotShared.Droid\Resources\Resource.Designer.cs
I use Xamarin.Forms v2.2.0.31 and all OxyPlot packages in version 1.0.0-unstable1983.
Am I missing something?
Note that there are 2 different project templates: Portable and Shared. In your post you mention both of them, so be clear about which one you're using. The specific example you're following is for a Portable project template. After adding the OxyPlot Nuget Package, I had to manually add OxyPlot and OxyPlot.Xamarin.Forms to the References of the Portable one. After that, it worked just fine. I'm using Xamarin.Forms 2.0.0.6482 and OxyPlot 1.0.0-unstable1983.
I added the PlotView using code:
App.cs:
public App()
{
PlotModel plotModel = new PlotModel { PlotAreaBackground = OxyColors.LightYellow };
plotModel.Series.Add(new FunctionSeries(Math.Sin, -10, 10, 0.1, "sin(x)"));
// The root page of your application
MainPage = new ContentPage {
Content = new PlotView {
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
Model = plotModel
}
};
}

Categories