I just downloaded the plugin XamJam.Screen and I have to implement it, the problem is that it is an interface.
That said, I've never implemented interfaces in c # programming, and I wonder if anyone can advise me how to implement it, I tried but without success, the following code:
namespace Fimap.WebPart
{
public partial class HomePage : ContentView
{
public HomePage()
{
InitializeComponent();
Screen xyz = new getScreen();
var w = xyz.Size.Width;
}
public class getScreen : Screen
{
public ScreenSize Size
{
get
{
return Size;
}
}
}
}
}
the problem is that size 0 me back around.
My goal is to take the width and height of the device.
You do not need to implement the interface yourself. If you installed the package through NUGET, you only need to call
var size = Plugin.XamJam.Screen.CrossScreen.Current.Size;
you can access the width and height of the screen with size.Width and size.Height
Please visit the project github home page and checkout the additional disclaimers on how the library works, provided by the author.
As you can see, the library is of limited use. There is probably a better way to achieve what ever it is that you are trying to do. Consider researching your actual use case / problem further.
Related
I am playing a video file that is 1280 x 720 in axVLCPlugin21 like this:
var file = #"C:\test\Amex.mov";
var convertedURI = uri.AbsoluteUri;
axVLCPlugin21.playlist.add(convertedURI);
axVLCPlugin21.playlist.play();
The video does play just fine but it is at the full size 1280x720 the window is 1/3 that size. My understanding is VLC should just automatically scale the video to the size of the axVLCPlugin21 control window. I am using the latest version of VLC 3.0.4 downloaded just a few days ago. I am using VS2015 and .NET 4.5 (I have tried .NET 4.6 and .NET 4.7 also. The full VLC application plays the video at the size of the window? Is there something I need to set in axVLCPlugin21 to get it to automatically scale the video to the size of the control window?
In other words what I want is fit video to window
I had same problem however my project is C++, in order to get that done you need to set video scale to 1 after the InitializeComponent() otherwise you get an exception.
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
this->axVLCPlugin21->video->scale = 1;
//
//TODO: Add the constructor code here
//
}
//Rest of the C++ file...
I assume that code would look like this in C#:
public partial class MyForm : Form
{
public MyForm()
{
InitializeComponent();
this.axVLCPlugin21.video.scale = 1;
//
//TODO: Add the constructor code here
//
}
//Rest of the C# file...
You could also wrap all your axVLCPlugin21 components in a method to set all its video scales and call that method after InitializeComponent() if you want something more elegant.
Let me know if this solution worked for you, because that worked for me.
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;
}
Heey,
I'm currently working on my second XNA/Monogame game for Windows 8/Metro but ran into a problem. We now came at the point which we need to store a highscore with a name attached to it so I need to handle the onscreen keyboard to get the info.
I searched through the forum and I found some topics related to this but no post with some example code or a description which helped me completely fixing my problem. I changed my project to a XAML template and I got a TextBox working in my GamePage but now I need to get the TextBox inside my game loop to read it out so I can save the name besides my score and I have currently no idea how to do this.
My current code of my GamePage.cs
public GamePage(string launchArguments)
{
this.InitializeComponent();
// Create the game.
_game = XamlGame<Main>.Create(launchArguments, Window.Current.CoreWindow, this);
txtTest.TextChanged += txtTest_TextChanged;
}
void txtTest_TextChanged(object sender, TextChangedEventArgs e)
{
Debug.WriteLine(txtTest.Text); //Write content to public string in Main.cs
}
I found out how I can write the content of the TextBox to a string inside my gameloop but now I'm stuck how I can control the TextBox his properties from inside my gameloop so I can set the Visibility and Focus. Do I need to create my own EventHandler which will watch if I set a Boolean or something?
Thanks in advance.
Greetings,
ForT3X
Disclaimer: Let me just say that I've never worked with Windows 8 XAML projects or the GamePage class before but after doing a little googling I think I understand enough to help.
It seems that your issue boils down to a circular dependency. You want 2-way communication between your GamePage and your Game class.
Communicating from the GamePage to the Game class is easy, because the GamePage is already responsible for creating the Game class and storing it in the _game member variable. Therefore, to send messages from your GamePage to the Game you just need to add a method to your Game class, for example:
void txtTest_TextChanged(object sender, TextChangedEventArgs e)
{
_game.SetHighscoreName(txtTest.Text);
Debug.WriteLine(txtTest.Text); //Write content to public string in Main.cs
}
Communicating back the other way (from Game to GamePage) is a little trickier, but it can be solved using an interface and property injection.
First, create an interface that belongs to your Game class. What I mean by that is; it lives in the same project and or namespace as the Game class. It might look something like this:
public interface IGamePageController
{
void ShowHighscoreTextBox();
}
Then, add a property to your Game class like this:
public IGamePageController GamePageController { get; set; }
Next, have the GamePage class implement the interface like so:
public partial class GamePage : PhoneApplicationPage, IGamePageController
{
//...
public void ShowHighscoreTextBox()
{
txtTest.Visibility = Visibility.Visible;
}
}
And finally, in the GamePage constructor you need to set the GamePageController property.
// Create the game.
_game = XamlGame<Main>.Create(launchArguments, Window.Current.CoreWindow, this);
_game.GamePageController = this;
Once you have this pattern in place, it's easy to add new ways for your Game and GamePage classes to communicate by adding more methods to the interface or Game class.
You can share a view model between the XAML page and your game.
The XAML page GamePage creates the instance of your game class. When it does you can also let the game class know about your view model.
_game = XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, this);
_game.XamlGameDataViewModel = new GameDataViewModel();
DataContext = _game.XamlGameDataViewModel;
There is more detail in my post Sharing your view model between Monogame and Xaml
If you need to store some values you should try with IsolatedStorage.
As MSDN says:
"Isolated storage is not available for Windows Store apps. Instead, use the application data classes in the Windows.Storage namespaces included in the Windows Runtime API to store local data and files."
You can find more information here.
Using Windows.Storage you should do something like this:
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
if (string.IsNullOrEmpty((string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["highscore"]))
{
localSettings.Values["highscore"] = highscore;
}
I see this in many projects that demonstrate the use of CAEmitterLayer, but how does it translate to MonoTouch aka Xamarin.iOS?
+ (Class) layerClass
{
//configure the UIView to have emitter layer
return [CAEmitterLayer class];
}
I know I can use UIView.Layer.AddSubLayer() but there seems to be performance impact.
I think you need to expose it to Obj runtime like the following.
[Export ("layerClass")]
public static Class LayerClass () {
return new Class (typeof (CAEmitterLayer));
}
For further info take a look to MonoTouch... CATiledLayer example.
Hope it helps.
P.S. Check the code. I've written without Xamarin Studio support.
I have been using Cosmos in Microsoft Visual C# 2008 to make primitive, TUI, operating systems. I wonder how to make a GUI in Cosmos. I know that it's possible, but I just want to know how to make it. Constructive criticism appreciated, insults not! Please reply with code (and comments in the code), because I am an absolute beginner, with only some knowledge of basic c# commands. Thanks!
I do not know what milestone your using, but I think this might work for you. You need this class level variable:
Cosmos.Hardware.VGAScreen screen;
And in your Init method:
screen = new Cosmos.Hardware.VGAScreen();
screen.SetMode300x200x8();
screen.Clear(0);
//done init vga screen
After that last comment, in your code, you can use this to set the color of a pixel:
screen.SetPixel300x200x8(uint x, uint y, uint color);
The color parameter is the color of the pixel in 256 color format (numbers 0 through 255). That's all you need to make a GUI. You need lots of math skills to make shapes, though.
There are also GUI API's with function's to make shapes.
Search on Google/YouTube or visit the discussion page on Cosmos' Codeplex page:
http://cosmos.codeplex.com/discussions
This is for 2020 Because this is a VERY good way todo this in cosmos. (USING CGS)
using System;
using System.Drawing;
using Cosmos.System.Graphics;
using Sys = Cosmos.System;
namespace Graphics
{
public class Kernel : Sys.Kernel
{
Canvas canvas;
protected override void BeforeRun()
{
canvas = FullScreenCanvas.GetFullScreenCanvas();
canvas.Clear(Color.Black);
}
protected override void Run()
{
Pen pen = new Pen(Color.White);
// DRAW stuff see https://www.gocosmos.org/docs/cosmos-graphic-subsystem/
}
}
}