I am programming some applications for the Windows Phone and am looking for some standard debugging practices that I cannot figure out how to do in a Windows Phone project in Visual Studio.
How can I print statements to the command line just for debugging purposes in a windows phone project?
Can I use MessageBox.show() (it seems that I cannot import System.Windows.Forms)
All help is appreciated!
you can use Debbugger.Log which will output to debug window
http://msdn.microsoft.com/en-in/library/system.diagnostics.debugger.log(v=vs.95).aspx
Indeed, you cannot import System.Windows.Forms from a Windows Phone project. In the case of WP7 you will program using a subset of Silverlight. With that in mind, there is a Message Box control in Silverlight for WP7 using the System.Windows namespace: http://msdn.microsoft.com/en-us/library/system.windows.messagebox(VS.95).aspx
I suggest that you approach your debugging needs by leveraging unit tests instead of printing to the Message Box.
For advanced tracing and logging you may want to take a look on
Silverlight and WP7 Exception Handling and Logging building block
NLog for Windows Phone
You can simply use Debug.WriteLine(Something); just like Console.WriteLine(Something);. The Something will automatically be converted to string. This is as simple as it can get.
As indicated, you can indeed use MessageBox control. It's present in System.Windows namespace. You can also use some third party toolkit like Coding4Fun if you need customized messagebox.
Related
I have an app I created in WPF. Current in WPF, I'm using the Microsoft.Win32.SaveFileDialog file picker to let the user select a file location to save to.
I'm in the midst of converting this app to a Windows Store compatible app, via the Desktop App Converter application. When I use the Win32 picker in the UWP-converted app, it just hangs and eventually crashes, so that doesn't seem to be happy.
It looks like there is a UWP-compatible file picker Windows.Storage.Pickers.FileSavePicker, which is available using the Nuget package UWPDesktop.
Unfortunately, this is giving me the following warning -
Type 'Windows.Storage.Pickers.FileSavePicker' can only be used in UWP apps, not Desktop or Centennial
This seems pretty clear to me, so, finally my question is What dialog picker am I supposed to use for a desktop converter UWP app?
Seems like there are 2 options -
There's some kind of 3rd type of file picker that I'm unaware of, that's compatible with both frameworks.
I use some kind of check in the app to see what framework is active (somehow) and use the appropriate file picker.
Thanks in advance!
You can continue to use the Win32 picker in your converted WPF app. That is supported and expected to work.
To answer why you are seeing a crash here:
If you have Office 2016 installed, there was recently a bug introduced with an Office update that is causing the file picker dialog to crash for converted apps. The fix for this bug should go out very soon in a servicing update.
To confirm that this is indeed the bug you are hitting you can look at the crash reports for your app, and you should see a crash in the module grooveex.dll.
Thanks,
Stefan Wick - Windows Developer Platform
I ended up building a sample app containing just the problematic dialog in an otherwise empty app, with the plan of sending it to Stefan over MS.
Of course, everything looked good, so I played with it a little more and eventually figured out what might have happened.
I was running some async code just before the dialog was executed, and it looks like that would fail silently, causing the app to hang indefinitely.
I don't think this will help anyone, just wanted to close the loop.
I'm trying to detect nearby devices using NFC or RFID from within a WPF application.
Microsoft's proximity API seems to be the right way to go:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465221.aspx
Unfortunately, I see no way to get it running inside a WPF application (or any other Desktop Technology that is). All examples refer to Microsoft store apps only.
From within a WPF application I cannot reference the Namespace
using Windows.Networking.Proximity;
Is it just a reference that I am missing? Is it possible to use the proximity API from a WPF application at all?
I finally found a sample project using the proximity API from within a WPF application:
http://code.msdn.microsoft.com/windowsdesktop/NFC-Editor-529ccda6
There is also a short tutorial included on how to use WinRT API's in WPF applications.
The basic steps:
Manually add a <TargetPlatformVersion>8.0</TargetPlatformVersion> line to the csproj file
Back in Visual Studio, add a reference to Windows/Core/Windows to the project references
Add a reference to the Windows Runtime assemblies to the project.
See above given link for details.
I believe that the Windows.Networking.Proximity.ProximityDevice class is not available in WPF Applications. If you look on the ProximityDevice class page on MSDN, you'll see that it is part of the Windows.Phone API:
The monitor image next to the phone image also leads me to believe that it is available for Windows Store Apps too. I'm guessing that (at present at least) the vast majority of desktop computers won't have any RFC hardware that could be used with this code and so that is why it is missing from the standard .NET dlls.
[2020 is here]
Procedure to prepare your Console/WPF project to call UWP APIs (both are OK):
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance
https://blogs.windows.com/windowsdeveloper/2019/09/30/windows-10-winrt-api-packs-released/
Heads up: You'll need to migrate the project from the packages.config management format to the PackageReference format
https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference#migration-steps
Description
I just start Windows Phone Development and I try to put some Logs in my application as I usually do in Android, I try to search through the Internet, but can't find anything useful.
Question
Is there in some native methods like Log.i(), Log.e() etc. in Android but for Windows Phone? I don't need to install some new libraries or something else.
Where did you expect to see the Log output?
You can try to use Debug.WriteLine() method, for example :
System.Diagnostics.Debug.WriteLine("Print something");
to print some value to Visual Studio output window.
I want to write a desktop gadget that will group icons on my desktop (using c# & WPF).
It will be a docked window that I can drag icons to it and they will stay their. Also there can be couple of this windows.
Where do I begin?
**I saw all the post here about it but I got lost. Please direct me to examples and explanation pages.
To expand on cevik's answer:
You cannot create WPF applications as gadgets BUT you have two options (which aren't as bad as you'd expect).
The reason is that widgets are composed mainly of web pages (HTML) and not executable (*.exe).
The problem of course is that WPF will only work with & produce executables.
First option - Windows API:
When I said you can't what I really meant is you can't use the Windows Vista/7 gadget platform to make your widgets.
However, you can always achieve a similar effect by using the Windows API.
The Windows API will let you do stuff to windows such as making them always on the background of other programs, which sounds to me like ~80% there (The rest would be stuff like making sure your window doesn't get re-sized or minimized, etc.).
Just as a note, the function you'd be looking for to make the window behind all other windows would be SetWindowPos (specifically the second parameter).
However make sure there isn't a library which already implements these stuff because it can be rather difficult (and consist of A LOT of surprises).
Second option - Silverlight
silverlight can be perceived as WPF for the web.
That obviously solves our problem.
However there is a cost to it, as expected.
Silverlight doesn't have all the features WPF has (possibly not all of the .NET framework as-well, not sure about that as I'm not really using it).
However it should be more than enough to get you by so you should definitely check it out.
Once you have your Silverlight application (and webpage) you'll have to create a manifest & install the gadget to your desktop. See here how to do so.
Maybe this will help you.
Template to easily get started on developing a Sideber Gadget using Silverlight 3.0 or 4.0 controls in C#.
I am working on an application using c# that will implement normal Text to Speech functionality using the Speech Synthesizer. One other functionality I want to implement is something similar to the Narrator Accessibility tool that comes with the Windows OS. The application should be able to go to background and read out information on what ever the mouse points at in any application.
Does any on know any library I can call or implement, that will make this possible? I am using Visual Studio 2010 Professional.
Thanks
Take a look at the System.Speech namespace - it should contain everything you will need.