Wednesday, February 28, 2018

How do you create a tabbed page control in Universal Windows Platform application?

Pivot control with its tabs helps you in navigating between items which can be content panes. Each item has a header to provide the text for the tab. The Pivot has a title and is the container of PivotItems.

The following 3 images show the navigation between three items.

In this app, the Pivot title is: Navigating with Pivot. The first PivotItem header is 'Home', the second PivotItem's header reads 'English' and the third PivotItem's header is 'Spanish'.

I have some text in English in the PivotItem with header 'English' and similarly a translation of the English text to Spanish in the PivotItem for Spanish. You can go from one page to the other easily. The images are from a deployment to a Lumia 950 phone.

Home is the first PivotItem in the app:

 Now navigated to English

Now navigated to the 'Spanish'


Now the code is very simple and uses only XAML statements

Here is the MainPage.xaml:

Note: Although this page does not throw an error. It builds, deploys and runs without an error but the Hyperlink in the first PivotItem is not active, although showing up as a hyperlink (underline and all!).
I am checking on this one. It is interesting to note that Hyperlink is not a control in the XAML tool set.

Tuesday, February 27, 2018

Which of the Mobile Emulators would you use with Windows OS?

This is not always clear.

It took a while to figure out this thing. I had Visual Studio 2017 Version 15.5.4 and ran into some design time problems as described in my post.

Following this question taking a suggestion from Stack Overflow, I installed Visual Studio 2017 15.5.6 skipping the suggested 15.5.5. It did help me to avoid the design time problem for a UWP project I was working on. I also updated it to version 15.5.7.

When I tried to view my app on an emulator, I did not find an emulator having used the latest version of Visual Studio in the deployment configuration. . Earlier I did not have this is problem before the upgrade.

Every time , I try to use an emulator to look at my app, I am lead to a Microsoft site for downloading an emulator.

According to UWP Forum on MSDN, there is no hard and fast rule for, 'What emulator with What version of Visual Studio 2017'. It is more to do with the version you are targeting and the build.

You can find this kind of information (you may have agreed for some target version while creating a project, but you can change later, if you need to) in the Project Properties page as shown.



These are the options on my computer.

If you try to change the version (using the drop-down menu, you get this message.


tarVers_3

The project reloads.

Another question that pops up answering the question in the title, is there a emulator running?  This is answered by looking up the Hyper-V Manager and turning on the desired emulator.



tarVers_4

The emulator is on but the deployment fails.


Now I change the target back to the older version.


tarVers_5

The project reloads.

Now I build and deploy to the same, previous emulator, 10.1.14393.0 1080p 6"
Now it deploys to the 6" emulator as shown. The JRelative app is displayed at the top.


tarVers_6

Note: When the emulator is up and running the deployment is faster. It is a productive practice as the OS to start in the emulator takes a tediously long processing time.

I turn off the 6" emulator and turn-on the 5". The next image shows the app deployed to Mobile Emulator 10.1.15254.0 720p 5" 1GB


This comes down to the result that there is no emulator for the OS build version 16299.



Monday, February 26, 2018

What is Amazon Web Services Greengrass?

It is a software solution to run local compute, messaging, data caching, syncing, and have Machine Learning inference capabilities.
Using AWS Greengrass connected devices (as in IOT for example) can run AWS Lamda functions, keep device data in sync and communicate with other devices securely in the Internet's unconnected scenario. This way using local compute you can interact with local resources, intermittent connections and updates with air updates.

AWS Greengrass involves both local resources as well as AWS. The development uses the same programming languages.

AWS Greengrass can:
  • filter data so that only necessary data is transacted to the cloud
  • Authenticates and encrypts device data at all points of connection(using AWS IoT Core)

Here is a  video how AWS Greengrass works.
Source:https://aws.amazon.com/greengrass/ 


Benefits:

  • Respond to Local events in Near Real-time
  • Operate off line
  • Reduce the Cost of running I0T Applications
  • Simplified Device Programming with AWS Lamda
Nokia's Multi-access Edge Computing (MEC) together with AWS Greengrass addresses the Enterprise use-case such as off shore Oil Exploration

https://networks.nokia.com/solutions/multi-access-edge-computing

Friday, February 16, 2018

How do you change LongFormat to WideFormat in R programming?

In my previous post you must have seen the difference between WIDE and LONG formats and also learnt how to convert a WIDE formatted data to LONG format.

In this post, you will see the converting of LONG format to WIDE format.

In this case you need to use the spread() function.

Let us start with the LONG formatted data of the previous post.
------------------------------
   Day Segment condition measurement
    1      AM      Jack        2.30
    2      AM      Jack        3.50
    3      PM      Jack        2.50
    4      PM      Jack        3.00
    1      AM      Jane        3.51
    2      AM      Jane        4.20
    3      PM      Jane        3.90
    4      PM      Jane        4.00
    1      AM       Tom        1.70
    2      AM       Tom        3.90
    3      PM       Tom        2.10
    4      PM       Tom        2.50
---------------------------------------
At first, read LONG data using read.table().

LongtoWide1.png

Use this code to convert this to WIDE format:
<- condition="" data_long="" measurement="" p="" spread="">Before you use spread(), you should have the tidyr library as shown here:


<- condition="" data_long="" measurement="" p="" spread="">LongtoWide2.png
<- condition="" data_long="" measurement="" p="" spread="">
<- condition="" data_long="" measurement="" p="" spread="">Note: Both gather() and spread() takes considerable time to process.

Thursday, February 15, 2018

What is the difference between WIDE and LONG format in R Programming?

First of all look at the same data in WIDE and LONG formats:

This is data in WIDE format:

Day  Segment  Jack  Jane  Tom
1      AM          2.5    3.5     1.7
2      AM          3.5    4.2     3.9
3      PM           2.5    3.9     2.1
4      PM           3.0    4.0     2.5

The same data in LONG format:
   Day   Segment   condition   measurement
1    1      AM        Jack           2.30
2    2      AM        Jack           3.50
3    3      PM        Jack           2.50
4    4      PM         Jack          3.00
5    1      AM        Jane          3.51
6    2      AM       Jane           4.20
7    3      PM       Jane            3.90
8    4      PM       Jane            4.00
9    1      AM      Tom            1.70
10   2      AM       Tom          3.90
11   3      PM       Tom           2.10
12   4      PM       Tom           2.50

You can convert from WIDE to LONG format as shown here:

Read the WIDE data using read.table() as shown here:
-----------------------
> data_wide <-read .table="" br="" header="TRUE," text="<br>+ Day Segment  Jack  Jane  Tom <br>+ 1   AM       2.3   3.51  1.7<br>+ 2   AM       3.5   4.2   3.9<br>+ 3   PM       2.5   3.9   2.1<br>+ 4   PM       3.0   4.0   2.5 <br>+ ">> data_wide
  Day Segment Jack Jane Tom
1   1      AM  2.3 3.51 1.7
2   2      AM  3.5 4.20 3.9
3   3      PM  2.5 3.90 2.1
4   4      PM  3.0 4.00 2.5
---------------------------------

R_wideData.png

Now you need to use a function gather() to do this conversion. gather() is in the
package deplyr. I installed the package tidyr that installs deplyr from CRAN mirror here:
https://cran.cnr.berkeley.edu/bin/windows
-----------
Load the library
> library(dplyr)
--------
Now do the conversion:
--------
>  data_long <- br="" condition="" data_wide="" gather="" jack="" jane="" measurement="" tom="">> data_long
   Day Segment condition measurement
1    1      AM      Jack        2.30
2    2      AM      Jack        3.50
3    3      PM      Jack        2.50
4    4      PM      Jack        3.00
5    1      AM      Jane        3.51
6    2      AM      Jane        4.20
7    3      PM      Jane        3.90
8    4      PM      Jane        4.00
9    1      AM       Tom        1.70
10   2      AM       Tom        3.90
11   3      PM       Tom        2.10
12   4      PM       Tom        2.50
>

R_longData.png

How to write a SWITCH statement in a UWP project?

SWITCH is a selection statement that selects a switch section among a number of switch sections based on a pattern match with the switch expression.


Switch.png

The default need not be the last case section, as it is evaluated last, no matter where it is found.
In the case constant (case sensitive).
  • constant is the value to test for, and it can be any of the following:
  • A bool literal, either true or false.
  • Any integral constant, such as an int, a long, or a byte. 
  • The name of a declared const variable.
  • An enumeration constant.
  • A char literal.
  • A string literal.
The following is a complete example in a UWP project called JSwitch:

In this example, the variable anim is set to 'bird'. It is case sensitive. Bird is not the same as bird. When the switch statement is run and it finds 'bird' in any of the case sections, it displays the corresponding case constant in the text box. Change 'anim' and run the app again, and the textbox displays the match.

The XAML page has just one TEXTBOX and a BUTTON. The button click runs the program MainPage.xaml.cs.

Here is the MainPage.xaml for the JSwitch project.


Here is the MainPage.xaml.cs code:



Wednesday, February 14, 2018

How do you access a selected item in XAML's ComboBox Control?

In Part 1, you added after following a few tasks the following to a  Blank UWP project.
  • Getting the ComboBox Control
  • Placing ComboBox on the Design area
  • Adding ComboBoxItems
ComboBox 4

In this post you will write code for an app consisting of a ComboBox, a Button and a TextBox so that when you select an item in the ComboBox and click the button, the selected item appears in the TextBox.

We already have a ComboBox with three items.
We will drag a BUTTON and a TEXTBOX from the Toolbox


ComboBox_8

And drop on the DESIGN pane as shown. The XAML markup is shown in the XAML Pane as shown.


ComboBox_9

We want to Select a ComboBoxItem and then click the BUTTON. This should get displayed in the TEXTBOX.

We add a click EVENT to the button by typing-in Click inside the BUTTON code as shown and choose 'NEW EVENT HANDLER'.


ComboBox_10

It will be named 'Button_Click' as shown.


ComboBox_11

The following will be added to the MainPage.xaml.cs page.

ComboBox_12

We provide names for the ComboBox ('cbx') as well as the TEXT ('txt') box. Now we add the following code to the above newly added code as shown.
-----
 private void Button_Click(object sender, RoutedEventArgs e)
        {
            txt.Text = cbx.SelectionBoxItem.ToString();
        }
-------

Now build, deploy and run the project on Local Machine. When the App is displayed, choose an item (herein, 'BIRD') from the ComboBox and Click the BUTTON, you will see it displayed in the TEXTBOX as shown (the UI is not designed well, it should be improved).


ComboBox_15