I have installed Visual Studio 2012 Express and the Mono SDK so I can do XNA game development.
I started reading about touch screen today and the Microsoft.XNA.Framework.Input.Touch namespace. I've put the following code into the Initialize() method of my main game class:
TouchPanelCapabilities tc = new TouchPanelCapabilities();
if (tc.IsConnected)
{
int i = tc.MaximumTouchCount;
}
but tc.IsConnected returns false. I'm developing on a touch Windows 8 tablet so can't understand why it would return false. Can anyone help?
You are initialising an empty structure. You need to call:
TouchPanelCapabilities tc = TouchPanel.GetCapabilities();
Then IsConnected should be true.
Related
The project I'm working on was using Xamarin Forms (3.4.0.x) Cross Platform, so obviously the iOS app had the UIWebView built in.
We decided to migrate to WKWebView, which required the Xamarin Forms 4.4 update so we proceeded to do that then added [assembly: ExportRenderer(typeof(WebView), typeof(Xamarin.Forms.Platform.iOS.WkWebViewRenderer))] to the AssemblyInfo.cs in our iOS app, like it says to do here. https://github.com/xamarin/Xamarin.Forms/pull/3346
Now I think that's all I need to do completely migrate to WK, but I have noticed that the app has slowed down significantly, taking ~5x as long to load a page, and on top of that, this loading icon stays on the screen even after the page is done loading
My questions are:
Did I migrate correctly, or are there any steps I'm missing/did wrong? Has anyone run into this loading icon problem before? Please ask me to clarify if I'm leaving information out, I'm new to Xamarin Forms so I'm not sure how to ask the best questions, and this is a big project I'm being introduced to. I have been told there is no custom iOS WebView Renderer though, so everything is done using the default WebView.
Thanks!
It is a native iOS issue caused because of the time it takes to detect phone numbers on the web page. So if you just disable that detection, it should work better.
Here's a sample of how you can do it in Xamarin:
var urlRequest = new NSUrlRequest(new NSUrl("https://www.gooogle.com"));
var config = new WebKit.WKWebViewConfiguration();
config.DataDetectorTypes = WebKit.WKDataDetectorTypes.Address;
var frame = new CoreGraphics.CGRect();
var webView = new WebKit.WKWebView(frame, config);
webView.LoadRequest(urlRequest);
If you followed the link you shared, you should be able to put the code inside the SetElement function of the WkWebViewRenderer. So your code would look like this:
var config = new WebKit.WKWebViewConfiguration();
config.DataDetectorTypes = WebKit.WKDataDetectorTypes.Address;
WebView = new WebKit.WKWebView(WebView.Frame, config);
There's an easier solution that just went public from the Xamarin team. All you need to do is update the Forms Nuget, Visual Studio, and Xamarin.iOS, and then:
... go to your iOS project, open the project properties and add this flag in the additional mtouch arguments field: --optimize=experimental-xforms-product-type.
I've been following the examples for using SkiaSharp with Xamarin Forms, particularly the section on using bitmaps. I'm doing this in Microsoft Visual Studio 2017 version 15.9.11. I'm only targeting Android currently.
This page https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/basics/bitmaps has a section on Loading a Bitmap Resource, where the bitmap is an embedded image resource in the project.
So, we add the image and make it type 'embedded resource'
and then run the example code to simply display the image on the canvas.
string resourceID = "SkiaTest.Media.monkey.png";
Assembly assembly = GetType().GetTypeInfo().Assembly;
using (Stream stream = assembly.GetManifestResourceStream(resourceID))
{
resourceBitmap = SKBitmap.Decode(stream);
}
All pretty simple, and it works fine if I run the code on my phone if it is connected via USB in the standard way (a Sony Z5) so the second in the list here, not the Player:
Here it is working via USB:
But if I try and use Xamarin Live Player (the first in the list above) then it crashes on this line:
using (Stream stream = assembly.GetManifestResourceStream(resourceID))
Note that the app runs fine in Live Player if I don't try and load the bitmap, it's only that line that triggers the crash, and only in Live Player.
So I wonder if anyone has any ideas what could be causing Live Player to fail over this issue? Is the resource not being copied to the phone? Does Live Player just not support this type of activity?
The reason you are facing this issue is that Embedded Resources are not yet supported by Xamarin Live player which is causing this exception.
More details can be found in the Troubleshooting Xamarin Live Player document.
I have built a UWP app, and a WPF app within the same solution. I am using the FullTrustProcessLauncher class to launch the WPF app from the UWP app. I am also using the AppServiceConnection class to allow the two apps to communicate with each other. This all works fine in a basic scenario. But once I start really developing my WPF app beyond the samples I can find I will need to start debugging in visual studio.
I've tried the following:
Set breakpoints within the WPF code.
Result: I did not expect this to work, and it did not.
Attach to the running WPF process once the UWP launches it.
Result: The "attach" button when the running WPF process is selected is grayed out.
I started investigating the new VS extension "Desktop Bridge Debugging Project" and followed along with samples and documentation.
Result: All of the samples I could find seemed to revolve around converting an existing WPF app to UWP. Because of this, I don't think this is a solution. I could be wrong...
Below is the relevant code for launching my WPF app from the UWP app:
int messageNumber;
private async void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (this.messageNumber == 0)
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}
this.messageNumber++;
await AppServiceManager.SendMessageAsync(
$"Message number {this.messageNumber}");
}
As I mentioned above, for now i'm just following the Microsoft examples. I would eventually like to add more complex code and be able to debug.
How else can I get debugging features for the WPF app launched from a UWP app?
Thanks
In order to debug the fulltrust process in your UWP project, you will have to start the UWP process without debugging (or detach the debugger from it). Then attach to the debugger to the fulltrust process and your breakpoints will be hit.
I realize this is not an ideal workflow, and we are working on improving this in a future update for VS.
Advanced Installer (a MSFT partner) provides now an extension for Visual Studio 2015 and 2017 that can build an AppX (along with your MSI/EXE) package from a single project and also enables debugging for your application with a few clicks - much simpler than current solutions.
- watch video demo -
After pausing local media (either in a silverlight app, the zune player or via system tray); when cold-launching any Silverlight application:
Expected Behaviour:
The Microsoft XNA MediaPlayer.Queue contains the appropriate media and the
player is in the paused state. MediaPlayer.GameHasControl should be true. The Zune player shows the media as expected.
Actual Behaviour:
The Microsoft XNA MediaPlayer.Queue is empty and the player is in the stopped
state. MediaPlayer.GameHasControl is sometimes in a variable state. The Zune player shows the media as expected.
Minimal reproducible code:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += OnMainPageLoaded;
}
private void OnMainPageLoaded(object sender, RoutedEventArgs e)
{
FrameworkDispatcher.Update();
// X reports as NULL when launching the app with an XNA song in the system tray in a paused state
// The XNA queue is empty. ActiveSongIndex is -1. PlayState is stopped.
var x = MediaPlayer.Queue.ActiveSong;
// ** Debug BREAK-POINT here - check value of 'x' **
// Following Play() below, the MediaPlayer.Queue.ActiveSong then becomes non-null as expected
var lib = new MediaLibrary();
MediaPlayer.Play(lib.Songs.First());
return;
}
}
}
Note: Any boiler-plate silverlight application shows this behaviour - however, the Microsoft Zune client always seems to show the media correctly in the paused state.
My assumption that this is therefore an issue in the Silverlight XNA wrapper...
Has anyone else seen this? Is there a workaround?
Many thanks,
Jon
Is there a method I can call to see if I am currently running in the emulator vs. running on an actual physical phone?
I need to run some code a bit differently when I am in the emulator (I have a mock gps location service).
You can get this from Microsoft.Devices.Environment.DeviceType
if (System.Environment.DeviceType == DeviceType.Emulator)
{
}
Hope that helps
For wp 7.5 Mango sdk, it has moved to the namespace Microsoft.Devices
if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator)
{
//Do Stuff
}