Showing posts with label UWP. Show all posts
Showing posts with label UWP. Show all posts

Sunday, August 12, 2018

Is the Visual Studio Community 2017 version 15.7.6 better than 15.7.5?

It was noticed while using Visual Studio 2017 Version 15.7.5 that C# templates were not found in their usual local in the New Project... window. This absence was raised in one of the Forums post and it was triaged by the Forum monitor.

Please review the following posts regarding this issue:

http://hodentekhelp.blogspot.com/2018/07/why-are-c-templates-missing-in-visual.html

http://hodentekhelp.blogspot.com/2018/07/why-are-c-templates-missing-in-visual_31.html

https://developercommunity.visualstudio.com/content/problem/301590/c-templates-are-mssing.html

As far as the unavailability of C# templates 15.7.6 is no better than its earlier version.

Since the version 15.7.5  did not work for C#, it was decided to try the next version, 15.7.6. This was available and it was installed  using the Visual Studio Community 2017 version 15.7.5.


Although C# templates were not found in their usual location they were available in the Other Languages node as shown.


A Blank App (UWP) project was created as shown.

An unhandled exception was thrown as seen above. The build process came up with some warnings but no errors.


The Deploy in Build menu item did not throw any errors and was deployed. There is a corresponding shortcut to the app in the All Programs.


However trying to run the app on the LocalMachine came up with this message.


The version 15.7.6 has the same problem as the 15.7.5 or something very nearly the same problem.


Friday, July 13, 2018

How come my Microsoft Lumia 950 not recognized by the File Explorer?

It has been quite strange the way Windows 10 works.

Few days ago Windows 10 was updated to Insider Preview Build 17692.rs_prerelease-flt.180625-1624 and now I cannot see my Microsoft Lumia 950 connected to the USB (there are three on this laptop) in the file explorer.

It is strange that I can connect to Flash Drives and WD's My Passport 1 TB drive connected to the USB drives.

Even stranger is, the fact that I can deploy UWP (Universal Windows Platform) projects from Visual Studio Community 2017 to the Microsoft Lumia 950 connected to the USB Drive.

I have done a hardware troubleshooting and restarted the laptop.

Still no good.

If I find a fix I will psot here for those who may hit the same wall.

Wednesday, July 4, 2018

UWP: Is there a way to find the device to which you are deploying a UWP Project?

You can find this information using the Windows.System as shown here:

Device_000

We can find the device to which the UWP is deployed using the above information.

Here is a Blank UWP Project's MainPage.xaml.

Device_0
I have a button and a text box. Button's click event finds the device information and writes to the text box using the click event shown here:

Device_00

When deployed to the machine (Windows 10 Pro Desktop), the response is as shown.

Device4.jpg

When deployed to an emulator:

The display shows the device info:


You can get the DeviceFamilyVersion as well. The code is inside the image.

On the emulator this is displayed.







Friday, May 4, 2018

UWP: How do you display a number entered as text as formated currency?

The entry you make in a text box control is of data type text and sometimes you need to format it as a currency with thousands separator while displaying.

Also, if the number of decimal places you enter is more than 2, you need to round it up to 2 in the output.

How do you code this in a UWP app?

Create a UWP page starting from a Blank UWP project with three controls as shown.





There are two text boxes and a button. You enter a number in the top textbox (txt1) and click the button, the formatted currency will be displayed in the bottom textbox(txt2).


The app displays as shown.

Now provide for a click event for the button and insert code as shown:

Convert_1

The string entered in txt1 is converted to data-type double, it is then 'rounded'. The rounded number is then formatted to show the currency symbol and the 1000's place delimiter you find, for example in Excel formatting.


Here is the app after entering a number and clicking the button.






Monday, April 23, 2018

UWP: How do you connect to SQLite from a Universal Windows App?

SQLite is the right relational daatabase with zero configuration for mobile apps. There is a recipe in Microsoft documentation on using a SQLite database in a UWP app. This should be quite straight forward given a recipe but there are problems. Probably because of a plethora of versions of just about everything.

This post is not about a successful follow up of the recipe to its successful end, but steps in the way of achieving, trying to document as much as possible, firstly to find where things did not happen as expected, secondly to make sure it works, at least for me.

The computer is Windows 10 Version 1803, build 17133.73
SQLite for Universal Windows Platform added via Extensions and Update

The Solution for the app, UWPDataTest:

Universal Windows project-UWPDataTest
DataAccessLibrary -DataAccesLibrary


UWPDataTestPost_0

Microsoft.NETCore.UniversalWindowsPlatform used in the DataAccessLibrary(version 6.0.8)


UWPDataTestPost_2

Installed Microsoft.NETCore.UniversalWindowsPlatform


UWPDataTestPost_2a

DataAccessLibrary referenced in UWPDataTest


UWPDataTestPost_3

Using DataAccessLibrary in MainPage.xaml.cs


UWPDataTestPost_4

Using DataAccessLibrary in app.xaml.cs


UWPDataTestPost_5

DataAccess class made static.


UWPDataTestPost_6

Cannot add using Microsoft.Data.SQLite to class library. Data is not an option. If you add it and try to build you get build errors.


UWPDataTestPost_7
Build errors: DataAccessLibrary.dll could not be found. The DataAccessLibrary build has errors.


UWPDataTestPost_8.png

Error persists after upgrading the SQLite version from within VS Studio 2017.


UWPDataTestPost_9.png

Microsoft Visual Studio 2017 Community edition used.


UWPDataTestPost_10.png

I am not sure where the sqliteSample.db is in the computer. It does not seem to be present anywhere, although search is not guaranteed to work always.


UWPDataTestPost_11.png

The problem at present seems to be related to the absence of SQLite on the computer. Perhaps there is an independent source for the database.
Another possible source of error could be the Insiders Preview build may not support the SQLite added.


Friday, April 20, 2018

UWP: How do you fix the missing Assembly References error?

This error showed up as soon as I tried to create a Blank UWP app in Microsoft Visual Studio 2017 Community. Of course you cannot create an application with missing references.


Problem.png

You first go and see what references are missing. This was my solution explorer when this happened.


Problem2

Well, it says references are missing but does not point to which one. However, the suggestion is to build the NuGet cache.

I opened up an app which had worked in another instance of VS 2017. I could see that the reference, Microsoft.NETCore.UniversalWindowsPlatform was missing.

In order to build the NuGet Cache right-click the Solution Explorer and invoke the Restore NuGet Packages menu-item as shown.


Problem3

Click on Restore NuGet Packages to open the NuGet window as shown.

Problem5

Click or search for Microsoft.NETCore.UniversalWindowsPlatform. Highlight the project from which the file is missing (in the right pane). Click Install.

You may get messages such as these, deal with them.

Problem 6


Problem 7

You should get a message that it has been restored as shown.


Problem4

Now you can verify that the reference has come back to the project.


Problem8



Tuesday, April 17, 2018

Are there ODBC drivers available for SQLite?

ODBC drivers are indeed available for SQLite databases. You can download the version you want from this link here. The driver has been tested with the following SQLite versions:

SQLite 2.8.17 
SQLite 3.22.0
Windows NT/2000 in MS Excel 97 (MSQUERY)

The author (Chris Wolf) of the driver has wrapped the SQLite C library into a ODBC driver.

These current versions may be of interes to you:

Current version
sqliteodbc.exe [http://www.ch-werner.de/sqliteodbc/sqliteodbc.exe]
sqliteodbc_w64.exe [http://www.ch-werner.de/sqliteodbc/sqliteodbc_w64.exe]
sqliteodbc-0.9996.tar.gz [http://www.ch-werner.de/sqliteodbc/sqliteodbc-0.9996.tar.gz]
sqliteodbc-0.9996-1.src.rpm [http://www.ch-werner.de/sqliteodbc/sqliteodbc-0.9996-1.src.rpm]

Monday, April 16, 2018

UWP: How do you access Page resources by code in an UWP app?

You can keep your resources, such as style, data etc. in different places on a page and then use them in your app either by declarative markup or using code.

This post shows how you may access resources in your "Page.Resources" using code.


PageResrcs_0

It has a resource which is a string and a key. The page has single TextBox named "txt1".
In the code behind you use the key to access the resource and send it to the text box.


PageResrcs_1

When you run the app this is what you see, the resource on the page appearing in the TextBox.



Saturday, April 14, 2018

UWP: How do you make all textboxes to have same properties in XAML?

All textboxes having the same properties such as font style, font size, bordering etc. is essential for making apps to have a good visual appeal.

There are various ways you can do it, but here is a simple example of doing it.

I will be using the example in my previous post as it will simplify writing for me.

I will be using the layout in the next image from my above post:


PlaceSpaceBetweenControls..._2

This is how you modify the XMAL markup for the MainPage.xaml

You include the style elements you want as a Gird attribute  inside your page. If the control you use is a textbox (there are four in the above layout) then all of them will get the same style.

 In the rendered app, you will get what you designed.



Friday, April 13, 2018

UWP:How do you control space between controls in XAML?

The easiest way is use the Margin in your control.

The syntax is Margin="left, top, right, bottom"

The next image shows code and design time layout where all textboxes have some space between them. The Button is still attached to the last textbox.


In this image the textboxes are separated from each other by equal spaces and also the 2,3 and 4 th box are left to their previous ones.

Enjoy!