Minggu, 31 Januari 2016

Honored to be Microsoft #MCC award - 2016

I was surprised on last Friday evening, when I saw my MSDN profile which has automatically added the Microsoft Community Contributor award Affiliations from Microsoft. Microsoft awarded me the MCC (Microsoft Community Contributor) award for the first time in my carrier. I am very pleased and share this with you all that my community contributions are recognized by Microsoft.



Thanks a lot to Microsoft, Microsoft MCC Award team for this special recognition. And also thank you all my community friends for your support and feedback throughout the year.
What is MCC Award?

People may want to know, what is this MCC Award? So, this point is for those who don’t know about the Microsoft MCC Award Programme. Here is a short snippet from the Microsoft profile affiliations:

The Microsoft Community Contributor (MCC) Award seeks to recognize notable contributors to Microsoft online community forums: TechNet, MSDN® and Answers in areas such as: moderation, content, translation/localization and feedback.

These valuable resources are enhanced by the efforts of Microsoft Community Contributors, who help other participants in a range of ways, such as providing helpful answers, translating online resources into local languages and serving as volunteer moderators.

Each day around the world, Microsoft Community Contributor recipients contribute to Microsoft online technical communities in a range of ways, including providing helpful answers, translating online resources into local languages and serving as moderators.

The MCC badge ends after ninety days (three months) from the date found within the welcome email.

Important Note:
It looks like MCC award is no longer given to TechNet and MSDN users to participate actively in the forums but rather automatically assigned to all MVPs

Please read below links for more info:
1. Information on Profile Affiliations
2. How to Become an MVP or MCC

Follow me always at  
Have a nice day by  :)

Sabtu, 23 Januari 2016

WinRT Windows Phone 8.1: Copy and past TextBox text within the app, beginners tutorials (C#-XAML)

Introduction:

TextBox control that can be used to display or edit unformatted text. And some times we may need to manipulate the TextBox text to create cut and paste within the app. So we can learn how to create custom ClipBoard functionality from this article

Requirements:

  • This sample is targeted for windows phone WinRT 8.1 OS,So make sure you’ve downloaded and installed the Windows Phone 8.1 SDK or later. For more information, see Get the SDK.
  • I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
  • This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows or Later.

Description:

Step 1:
1. Open Microsoft Visual Studio Express 2013 for Windows (or) later.
2. Create new windows phone WinRT project using the "Blank App" template available under Visual C# -> Store Apps -> Windows Phone Apps. (for example project name : WinrtCut_Paste)
Step 2: And lets add below code in MainPage.xaml, which is having mainly three buttons for performing copy,cut & paste operation on entered text in TextBox.
  1. <Grid>  
  2.         <StackPanel>              
  3.             <!--Sample Tile-->  
  4.             <TextBlock Text="WinRT Copy & Past Text:" FontSize="25" />  
  5.               
  6.             <!--Textbox for entering text-->  
  7.             <TextBox Name="TbxEnteredText" Header="Entered Text:" MinHeight="100" TextWrapping="Wrap" AcceptsReturn="True"/>  
  8.               
  9.             <!--Three buttons for copy,cut & paste operations-->  
  10.             <Button Content="Copy" HorizontalAlignment="Stretch" Click="CopyClick"/>  
  11.             <Button Content="Cut" HorizontalAlignment="Stretch" Click="CutClick" />  
  12.             <Button Content="Paste" HorizontalAlignment="Stretch" Click="PasteClick"/>  
  13.         </StackPanel>  
  14.     </Grid>  
Press F5 to run the our project and screen could be like below:


Step 3: 
1. How to copy text from TextBox?
In generally to select text, we need to double tap on textbox text, In TextBox,we have property like SelectedText can used to get content of the current selection in the text box. So I taken one global string variable name is ClipboardText for storing selected text of TextBox
  1.        private string ClipboardText;  
  2.         private async void CopyClick(object sender, RoutedEventArgs e)  
  3.         {  
  4.             if (TbxEnteredText .SelectedText != "" && ClipboardText != "")  
  5.             {  
  6.                 //Copy selected text to CustomClipboard  
  7.                 this.ClipboardText = TbxEnteredText .SelectedText;  
  8.             }  
  9.             else  
  10.             {  
  11.                 MessageDialog messageDialog = new MessageDialog("Please select text for copy operation");  
  12.                 await messageDialog.ShowAsync();  
  13.             }  
  14.         }  

2. How to cut text from TextBox?
When user can select the text by double tap on it and press the cut operation button, we need to remove the selected text from the textbox.
It means we need to replace the TextBox original text with the text before and after the selection like below:
  1. private async void CutClick(object sender, RoutedEventArgs e)  
  2.         {  
  3.             if (TbxEnteredText .SelectedText != "" && ClipboardText != "")  
  4.             {  
  5.                 //Copy selected text to CustomClipboard  
  6.                 this.ClipboardText = TbxEnteredText .SelectedText;  
  7.   
  8.                 var removeAt = TbxEnteredText .SelectionStart;  
  9.   
  10.                 var AfterSelectionLocText = TbxEnteredText .Text.Substring(removeAt + TbxEnteredText .SelectionLength);  
  11.   
  12.                 var BeforeSelectionLocText = TbxEnteredText .Text.Substring(0, removeAt);  
  13.   
  14.                 TbxEnteredText .Text = BeforeSelectionLocText + AfterSelectionLocText;  
  15.   
  16.                 TbxEnteredText .SelectionStart = BeforeSelectionLocText.Length;  
  17.             }  
  18.             else  
  19.             {  
  20.                 MessageDialog messageDialog = new MessageDialog("Please select text for cut operation");   
  21.                 await messageDialog.ShowAsync();  
  22.             }  
  23.         }  

In above code, I am using SelectionStart property which is useful to get character index for the beginning of the current selection.

3. How to paste text in TextBox?
Upto now, when user copy the text or cut the text from textbox, it can stored in our global string is 'ClipboardText '. So to perform paste operation, first we need to get position where user place the cursor on textbox and after that we need to place the our ClipboardText on that selection position.
  1. private async void PasteClick(object sender, RoutedEventArgs e)  
  2.        {  
  3.            if (ClipboardText != "" && ClipboardText != null)  
  4.            {  
  5.                var SelectionLocation = TbxEnteredText .SelectionStart;  
  6.                var BeforeSelectionLocText = TbxEnteredText .Text.Substring(0, SelectionLocation);  
  7.                var AfterSelectionLocText = TbxEnteredText .Text.Substring(SelectionLocation + TbxEnteredText .SelectionLength);  
  8.   
  9.                TbxEnteredText .Text = BeforeSelectionLocText +  
  10.                          this.ClipboardText +  
  11.                          AfterSelectionLocText;  
  12.   
  13.                TbxEnteredText .SelectionStart = SelectionLocation + this.ClipboardText.Length;  
  14.                TbxEnteredText .SelectionLength = 0;  
  15.            }  
  16.            else  
  17.            {  
  18.                MessageDialog messageDialog = new MessageDialog("No selected text for paste operation");  
  19.                await messageDialog.ShowAsync();  
  20.            }  
  21.        }  
4. Demo:
4.1 Type some text in TextBox like below:
4.2 double tap on text which you want to copy, and press copy Button
4.3 Place cursor where you want to paste the your copied text and click on the paste button.




Important Notes:
1. In WinRT, there are more properties added for TextBox control compare to Silverlight platfrom (Ex: Header, PlaceholderText..etc)
2. Just reminder is, this sample can also run for windowsphone silverligh platform. Because this  sample used very basic coding to perform copy,cut & paste operation within the app.
3. This sample will be work on windows phone 8.1 OS devices or later. and this sample was tested in Emulator,Nokia Lumia 530, Nokia Lumia 735& Microsoft 535.
Custom ClipBoard
FeedBack Note:
Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)


Rabu, 06 Januari 2016

Windows Store Apps : How to communicate with C# code from WebBrowser javascript and vice versa, beginners tutorials (C#-XAML)

Introduction:

In previous article I wrote an article about silverlight windows phone and which can explain you about 'Communication between C# code and WebBrowser html content'. In this article we can learn how to do same thing in WinRT windows phone platform

Requirements:

  • This sample is targeted for windows phone WinRT 8.1 OS,So make sure you’ve downloaded and installed the Windows Phone 8.1 SDK or later. For more information, see Get the SDK.
  • I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
  • This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows or Later.

Description:

Step 1:
1. Open Microsoft Visual Studio Express 2013 for Windows (or) later.
2. Create new windows phone WinRT project using the "Blank App" template available under Visual C# -> Store Apps -> Windows Phone Apps. (for example project name :WindwsCsharpvsJavascript)

Step 2: And lets add below code in MainPage.xaml, which is having one WebView control is for displaying html content , and one Button is for loading html on Click event.

  1. <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">  
  2.         <StackPanel x:Name="LayoutRoot" Background="LightBlue">  
  3.             <WebView  x:Name="WebBrowserName" Height="400" Margin="5" />  
  4.             <Button x:Name="Button1" Content="Call javascript function from c#" Click="Button1_Click" />  
  5.         </StackPanel>  
  6. </Grid> 

Note: In WInRT no need to set property IsScriptEnabled="True". Because for WebView control we don't have property like IsScriptEnabled. And by default ScriptNotify event will be fire when javascript function invoked by webview content.
Step 3: Create Html page in project (Ex:LocalHTMLPage.html) and add your html content in it.
Example html content:


  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head>  
  3.     <title></title>  
  4.     <script type="text/javascript">  
  5.         function JavaScriptFunctionName() {  
  6.             window.external.notify('JavaScriptFunctionName');  
  7.         }  
  8.     </script>  
  9. </head>  
  10. <body>  
  11.     <h1 style="color:red;font-size:35px;">Communication BTW JavaScript & C# in windows phone WinRT app.</h1>  
  12.     <input id="Button1" type="button" style="width:100%;height:100px;font-size:50px;" value="Call C# function from Html Button" onclick="window.external.notify('CsharpFunctionName')" />  
  13. </body>  
  14. </html>  

and project reference folder should be like below:


Step 4: In general, in WinRT windows phone we have different ways to load html content in WebView control


  1.  //Load local file using 'Source' property  
  2.            WebBrowserName.Source = new Uri("ms-appx-web:///LocalHTMLPage.html");  
  3.   
  4.            //Load local file using 'Navigate' method  
  5.            WebBrowserName.Navigate(new Uri("ms-appx-web:///LocalHTMLPage.html"));  
  6.   
  7.            //Load html string using 'NavigateToString' method  
  8.            WebBrowserName.NavigateToString("<Html><Body><h1>Load local html string in windows phone winrt app.<h1><Body></Html>");  

However in constructor, we need to load html content in WebView before we need to register it for ScriptNotify event like below:


  1. public MainPage()  
  2.        {  
  3.            this.InitializeComponent();  
  4.            //Load local html file using 'Navigate' method    
  5.            WebBrowserName.Navigate(new Uri("ms-appx-web:///LocalHTMLPage.html"));  
  6.   
  7.            //Regester webbrowser control for script notify event    
  8.            WebBrowserName.ScriptNotify += WebBrowserName_ScriptNotify;  
  9.        }  

Step 5:
Calling C# Code from Javascript :
In  SciptNotify event we can get parameter values, once specific function is calling from html button click. Lets see above html page,there I written window.external.notify('CsharpFunctionName') is for calling C# function from html button onclick event. and so we will get this value on ScriptNotify event. After that in IF condition we can do anything as per our requirement, here in this sample i am trying to navigate to another windows phone page. 


  1. async void WebBrowserName_ScriptNotify(object sender, NotifyEventArgs e)  
  2.         {  
  3.             if (e.Value.StartsWith("CsharpFunctionName"))  
  4.             {  
  5.                 Frame.Navigate(typeof(NextWindowsPage));//Calling C# function from javascript  
  6.             }  
  7.             else if (e.Value.StartsWith("JavaScriptFunctionName"))  
  8.             {  
  9.                 Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Calling javascript function from C#");  
  10.                 await dialog.ShowAsync(); //  
  11.             }  
  12.         }  

Calling Javascript Code from C#:
In our html page we have javascript function name is JavaScriptFunctionName  ,so if we want to call this javascript function from C#. We need to write below code on windows phone button click event.


  1. private async void Button1_Click(object sender, RoutedEventArgs e)  
  2.         {  
  3.             await WebBrowserName.InvokeScriptAsync("JavaScriptFunctionName"new string[] { "" });//Calling javascript function from C#  
  4.         } 
6. Output:

Important Notes:
1. We don't have IsScriptEnabled property in WinRT webview control, and by default webview can trigger ScriptNotify event when javascript function is invoked from it content. 
2. Just reminder is WebView control in windows phone WinRT is used for displaying html content, and in silverlight windows phone we called it as 'WebBrowser' control.
3. This sample will be work on windows phone 8.0 OS devices or later. and this sample was tested in Nokia Lumia 735 device & Microsoft 535.
WindowsWebBrowser
FeedBack Note:
Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)