Pages

Tuesday, December 27, 2011

How to get all Media Library pictures name in Windows Phone 7.

PictureCollection pc = new MediaLibrary().Pictures;

foreach (Picture item in pc)

{

MessageBox.Show(item.Name);

}


Friday, December 23, 2011

UriMapping in Windows Phone 7

In this article we are discussing about UriMapping concept in Windows Phone 7. As your application grows you will probably have to use folders and perhaps subfolders in order to keep the project structure easy to follow.

The navigation system within a Windows Phone 7 application allows you to use UriMapping to convert a short URI into the full path of the XAML page within your project. UriMapping is a mechanism; that allows us to implement developer friendly navigation between Windows Phone 7 applications.

What is UriMapping?

UriMapping is an alias of physical path of views in WP7 project, which allows developer to mapped entire views using UriMapper class object. It helps developer to modify the project structure and without making any changes in the navigation code.

To developer friendly term, Uri-Mapping mechanism is used to hide the actual (physical of a file path) navigation structure of application and it also provides easy way to pass data through parameters to the pages by using query string between one page to another page.

Let’s take an example for the same; in this case we have created three xaml pages like (Facebook.xaml, PramValues.xaml, Twitter.xaml).

In this project structure we have one UI directory to keep all views. See below picture.

1

There are some basic steps to achieve this functionality in the project.

Step-1: Create an instance of UriMapper class object in App.xaml.cs class and add URI mapping items in Constructor for the Application object. And now add UriMapper object to PhoneApplicationFrame’s object RootFrame’s property UriMapper. See below code snippet for the same.

public App()
{
// Global handler for uncaught exceptions. 
       UnhandledException += Application_UnhandledException;
       // Standard Silverlight initialization
       InitializeComponent();
       // Phone-specific initialization
       InitializePhoneApplication();
 
// URI Mapping 
var appNavigationMapper = new UriMapper();
appNavigationMapper.UriMappings.Add(CreateUriMapping("Facebook","/UIs/Facebook.xaml"));
appNavigationMapper.UriMappings.Add(CreateUriMapping("Twitter", "/UIs/Twitter.xaml"));
appNavigationMapper.UriMappings.Add(CreateUriMapping("About/{value}/{value1}", "/UIs/PramValues.xaml?id={value}&name={value1}"));
 
RootFrame.UriMapper = appNavigationMapper;
 
// Show graphics profiling information while debugging.
if (System.Diagnostics.Debugger.IsAttached)
{
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = true;
 
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
 
// Enable non-production analysis visualization mode, 
// which shows areas of a page that are handed off to GPU with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
 
// Disable the application idle detection by setting the UserIdleDetectionMode property of the
// application's PhoneApplicationService object to Disabled.
// Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
// and consume battery power when the user is not using the phone.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}         
 
}




Step-2: Now we are developing UI (user interface) for accessing the particular UI using UriMapping mechanism. In this example I have added three buttons for like Twitter, Facebook and Param(s) to call the specific UI with an action of appropriate command button. Here is UI design with xaml code.

<Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Uri Mapper" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>
        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Twitter" Height="72" HorizontalAlignment="Left" Margin="40,68,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" Background="#FFEB3636"></Button>
            <Button Content="Facebook" Height="72" HorizontalAlignment="Left" Margin="240,209,0,0" Name="button2" VerticalAlignment="Top" Width="160" Click="button2_Click" Background="#FFEB3636"></Button>
            <Button Content="Param(s)" Height="72" HorizontalAlignment="Left" Margin="42,365,0,0" Name="button3" VerticalAlignment="Top" Width="160" Click="button3_Click" Background="#FFEB3636" />
        </Grid>
    </Grid>
mainPageDesign

Step-3: At the end we will call the URI mapping using NavigationService.Navigate() method. In this example I have created a generic method for calling specific UI call by specific alias of UriMapping name as we mentioned in the App.xaml.cs class constructor. See below code snippet.

private void DoNavigate(string NavigatePageName)
{
    this.NavigationService.Navigate(new Uri(NavigatePageName, UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
DoNavigate("Twitter");
}
private void button2_Click(object sender, RoutedEventArgs e)
{
     DoNavigate("Facebook");
}
private void button3_Click(object sender, RoutedEventArgs e)
{
     DoNavigate("About/2/pavan"); // With two parameters
}


The Following code shows an example of Uri mapping process. When user pass “About/2/pavan” it will be navigated to relative address “/About/2/pavan” which is a fake address. That fake address is mapped by “About/{value}/{value1}” to “/UIs/PramValues.xaml?id={value}&name={value1}”


How to get Query string values in Navigated Page.


Using NavigationContext is used to retrieve the specific value about the passing by the parameters. See below code for the same.


void PramValues_Loaded(object sender, RoutedEventArgs e)
{
   // Method - 1
   textBlock1.Text = string.Format("Id= {0}", NavigationContext.QueryString["id"]);
   textBlock2.Text = string.Format("Name= {0}",NavigationContext.QueryString["name"]);
   // Method - 2
   var values = NavigationContext.QueryString.ToArray();
   foreach (var item in values)
   {
      System.Diagnostics.Debug.WriteLine("Key : " + item.Key + "  " + "Value : " + item.Value);
   }
}


Step-4: Press F5 to execute the application.


~ Happy Coding Smile


Source Code

Tuesday, December 13, 2011

Final BIWUG Session for 2012 – SharePoint 2010 Variations (Level 400)

In order to finalize the SharePoint multilingual sessions BIWUG ( the Belux Information Worker User Group) – www.biwug.be has a special evening planned.

This session will cover level 400 topics on SharePoint 2010 Variations. The following topics will be covered: concepts and internals of variations (page vs. site variations), concepts and internals of configuration, variation Timer Jobs internals, different flavors of variations (automatic, manual, different site templates, same site templates, …), the “famous relationships list”, stsadm and PowerShell commands which assist variations, changes between 2007 and 2010.

Demos will be performed while some coding aspects will be covered. It will be shown how variations can be used for other purposes than just implementing multilingual solutions

Pascal Benois is a SharePoint Premier Field Engineer at Microsoft.
He is into SharePoint technologies from the early days and has a strong focus on custom applications, ECM and multilingual deployments.

Date: 21/12/2011 at 18:00, you are welcome at 17:30
Location: Microsoft Belgium offices
Registration link: http://biwug2112-estwhdr.eventbrite.co.uk/

Tuesday, November 29, 2011

How to install SharePoint Server 2010 Language Packs on Windows 7

When trying to install SharePoint Server 2010 Language Packs on top of Windows 7 you might receive the following error – “Setup is enable to proceed due to the following errors: this product requires Windows Server 2008 Service Pack 2 …” – to work around this you can use the same procedure with the language pack installation files as the one outlined for the normal SharePoint installation on Windows 7 – a great walkthrough is Setting up the Development Environment for SharePoint 2010 on Windows Vista, Windows 7 or Windows Server 2008. Listed below are the exact steps

  • Copy the language pack installation files to a folder on your computer where you are installing SharePoint and doing your development

  • Extract the installation files by opening a Command Prompt window, and then typing the following command at the directory location of the folder where you copied the installation files in the previous step.

          • For SharePoint Foundation 2010  - c:\SharePointFiles\SharePointLanguagePack.exe /extract:c:\LangPack
          • For SharePoint Server 2010 -c:\SharePointFiles\ServerLanguagePack.exe /extract:c:\LangPack

  • Using a text editor such as Notepad, open the installation configuration file, config.xml, located in the following path: c:\LangPack\files\Setup\config.xml and add <Setting Id="AllowWindowsClientInstall" Value="True"/> inside the <configuration> tag

  • Proceed with the installation using the normal way of working

 

Friday, November 11, 2011

Quick Tip – Solving WP7 DatePicker and TimePicker missing icons problem

To see the correct ApplicationBar icons in the DatePicker and TimePicker, you will need to create a folder in the root of your project called "Toolkit.Content" and put the icons in there. The toolkit provides the necessary icons, but you have to copy them from the PhoneToolkitSample project. They must be named "ApplicationBar.Cancel.png" and "ApplicationBar.Check.png" and the build action must be "Content"!

Source: WP7 DatePicker and TimePicker in depth | API and Customization

Thursday, November 10, 2011

BIWUG session about the SharePoint 2010 Multilingual User Interface on 30th of November

 

Doing a SharePoint project in a multilingual environment can be tricky. In this BIWUG session we will focus on how the new MUI (Multilingual User Interface) allows for multilingual collaboration scenarios. We will show you how MUI and the SharePoint variations framework relate to each other. Next to showing the out of the box features we will do a deep dive for developers explaining how to use the MUI framework in SharePoint custom solutions. The session will wrap up with some best practices and pitfalls as well as a round the table discussion to exchange ideas.

Hope to see you there.

Agenda:

18:00-18:30 – Welcome and snacks

18:30-19:30 – SharePoint MUI – Part I (Speakers: Andy Van Steenbergen & Joris Poelmans)

19:30-19:45 – Break

19:45:20:45 – SharePoint MUI – Part II (Speakers: Andy Van Steenbergen & Joris Poelmans)

20:45 – … SharePint!


Register for BIWUG3011 : SharePoint 2010 Multilingual User Interface in Mechelen, Belgium  on Eventbrite

Monday, November 7, 2011

Presenting SharePoint 2010 - to pie or not to pie?

I recently found an interesting discussion about the SharePoint pie – to pie or not to pie?  Most of you have probably use the image depicted below in presentations to potential customers – but is that such a good idea?

Here are some of my ideas about this:

  • The SharePoint 2010 pie makes sense to talk to technical people who have worked with previous versions of SharePoint – also check out this one – Making sense of the SharePoint 2010 pie
  • It is probably not the pie that matters but the story behind it – the translation to the business context of a specific customer which makes a difference - an excellent article about this is Effectively communicate the power of SharePoint to a business audience
  • I haven’t found a comparable compelling graphic yet to explain such a diverse product (or platform) such as SharePoint – so I will probably still be using it for quite a while.
  • The terms used within the pie such as composites, insights are probably not known with business users but they are commonly used by all SharePoint professionals so it makes it for customers  sometimes a little simpler to compare consultants and their sales pitch.

Please leave a comment with your idea about this or fill in this poll



Supporting links for SharePoint Foundation 2010 Development training Part 2

Module 8 – Sandboxed solutions

Module 9 – SharePoint Web Services

Module 10: LINQ and REST

Module 11: Building webparts

Wednesday, October 26, 2011

WP7 A better InkPresenter using XNA

  Last week I was at SMAU Italia  together with Matteo Pagani giving a hand at Windows Phone 7 labs and having a good time with my friends at Microsoft. I also got the pleasure to meet Ben Riga. One of the attendees at the laboratory raised a really good question about the performance of the InkPresenter in WP7. He is using the control to capture a signature, but if you are pretty fast (usually people when they do their signature are fast) the result is "ugly" and not really usable. You won't get a smooth curve, but something like this:


 This screenshot is taken in the emulator, but on the real device the curve looks worst and it's easy to reproduce this behavior. I took this "problem" as a challenge (two nights of work and now the third to write the post) convinced that I can get better results with a mix between XNA and Silverlight, mix that in Mango is possible. T
 The main problem is the number of points returned by the event MouseMove of the InkPresenter control which is not enough points to draw a decent curve.
  The first thing I've tried in the XNA version was to use the TouchPanel.GetState() but I was surprised to see that I get the same number of sampling points as the MouseMove in InkPresenter. The things improved a lot when I've used TouchPanel.ReadGesture() with GestureType.FreeDrag. Using these sampling points as StylusPoints for the InkPresenter the situation improved a little:


 The black line is the one obtained with MouseMove and the red one is the one obtained with ReadGesture.The result is better, but not satisfying. The only way to further improve the result was to manually draw the curve without InkPresenter. I've have used BezierSegment to draw the curve. Without any processing this would be the result:


The new curve is the blue one which is better than the others, but it is still not smooth in some points. This is because a Bézier path is smooth if each endpoint and its two surrounding control points lie in a straight line. In other words, the two tangents at each Bézier endpoint are parallel.



There is more than one approach to solve this behavior and I've implemented two (with all the mathematics I felt back at the University http://en.wikipedia.org/wiki/B%C3%A9zier_curve). 

The first is an algorithm for Automatically Fitting Digitized Curves with the Douglas Peucker algorithm to reduce the number of points (http://stackoverflow.com/questions/5525665/smoothing-a-hand-drawn-curve).

The second one uses Bézier splines which creates the First and Second control points for each Bézier segment http://www.codeproject.com/KB/graphics/BezierSpline.aspx . 

With both algorithms the results are pretty good:


If you are interested to play with the sample you can change the following parameters:

double PhilipSchneiderTolerance = 0;
double PhilipSchneiderError = 4;
-used when the fitting algorithm is PhilipSchneider (run this sample http://cid-c27e99281f78a67a.office.live.com/self.aspx/Public/Simplify.zip on the desktop to understand what changes when you change the Tolerance and the Error)

 private bool _showPoints = false;
-shows or hides the points read by ReadGesture
        
private bool _showOtherCurves = false;
-shows or hides the InkPresenter curve using MouseMove and ReadGesture

private FitCurveAlgorithm _algorithm = FitCurveAlgorithm.PhilipSchneider;
-changes the fitting algorithm: None, BezierSpline, PhilipSchneider




P.S. The project still needs some working/polishing in order to be used in production, but that is the simple part so... HAVE FUN

NAMASTE

Thursday, October 20, 2011

Skydrive Library for Windows Phone v1

   I've started this project before Build. At that time I didn't know what Microsoft was preparing for the skydrive REST Api so there was no way to fully access your skydrive folders and files. The idea was to be able to get the modified files (word, excel) from Skydrive back to the dropbox account (a lot of people requested that feature and, as you probably know, in Mango you can save the files directly to your skydrive account). So I've started by contacting the people that already had developed applications that use Skydrive for Windows Phone 7 ( it doesn't make sense to reinvent the wheel if you can borrow or buy one) . I've found 2 applications: Sky Wallet and the other Skydrive Player and the answers from the developers were not what I was expected: the first one pointed me to Skydrive.Net which is(was) unusable for Windows Phone and then didn't replied to my other emails (so I understood it was disturbing for him to share his work) and the other said that the source code was not really clean (so more or less I don't want to share it). The only option was to start digging up and find out how they did it (that day I've also promised to myself that i will publish the code even if this will mean that the application I have in the marketplace will loose some value) It took me more than I expected  to understand and implement the mess (for me it's a mess) behind the WebDAV, but the results are not bad ... it works. The source code is quite a mess but it's free and you can use it (if I wait to have time to "clean" the code I will never publish the library). When the REST api will be out of beta (you cannot publish an app with the beta sdk) this library will be obsolete, but till then you can use it in your applications and they will pass certification (at least mine did ... till now ). The list root folder method is slow because I have to call two methods in order to have all the files and folders. You will also find a test project that will show you how to browse your skydrive. Creating folders and uploading files are not implemented in this version and it doesn't make sense to implement them because it will be much easier to do it with the REST api. If you need this functionality contact me and I will point you in the right direction.
  The project is published on Codeplex: http://wp7skydrive.codeplex.com/
  
  If you have questions, need support, or want to improve the library please let me know. If you wanna see a better integration of the library than the simple test project you should buy my dropbox client Boxfiles :) .

NAMASTE

DropBox library for Windows Phone 7 v1.1

 I have just published an updated version of my Dropbox client on CodePlex. You can download it here. I have rewritten the library from scratch (took out all dependencies - Json.Net and Hammock, added the download progress event and a lot of other things that I cannot even remember). It's faster, better and it's the exact same library I am using in my Dropbox application . I really hope that it will be useful for your projects and hope your projects will not be something similar to Boxfiles.
   That's all folks!

P.S. It doesn't have a test project, but you can use the one in the first release. It should be easy to use and pretty intuitive. If you find bugs or want to improve the library please let me know


NAMASTE!

Saturday, October 8, 2011

How to make a call in Windows Phone 7

 

00

In this article, I am going to describe how to make a call in windows phone 7 using managed API.

Objective of this article to make a call programmatically, sometimes application has specific requirement to make a phone call from application; in that scenario we can take the leverage of Microsoft managed API Microsoft.Phone.Tasks (namespace) allows to access PhoneCallTask API to make a call in windows phone.

Basically PhoneCallTask API allows an application to launch the Phone application. Use this to allow users to make a phone call from your application.

Let’s take an example to make a phone call from application. Add a Button to the default XAML which is gifted by MS Visual Studio when you start a new Windows Phone 7 Silverlight application. See the below xaml here.

 

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
      <Button Content="Phone Call" Height="82" HorizontalAlignment="Left" Margin="140,234,0,0" Name="btnCall" VerticalAlignment="Top" Width="auto" Click="btnCall_Click" />
</Grid>

XAML will generate the UI (user interface) that look like see below screen.

01

Now initialize the PhoneCallTask task object in the constructor of page, to avoid the memory overhead so I initialized in the constructor.

PhoneCallTask phoneTask = null;
// Constructor
public MainPage()
{
    InitializeComponent();
    phoneTask = new PhoneCallTask();            
}

The PhoneCallTask class contains two core properties like DisplayName, PhoneNumber and one show method, which allows us to shows the phone application. To make an actual call though the application.

Now double click the button control and click event handler got added to button control object. In the button click event set the display name and phone number which you want to make a call. And calls a *Show()* method of phone task object. See below mentioned code snippet.

private void btnCall_Click(object sender, RoutedEventArgs e)
{
  phoneTask.DisplayName = "Pavan Pareta";
  phoneTask.PhoneNumber = "+911234567890"; // put your desired phone number here
  phoneTask.Show();
}

Now the application is get ready to execute. When the user clicks on the button, phone dial will appear the phone user has to click the on *call* button then only we can make a call.

See blow screenshots

0203

Download source code here.

Thank you for your time.

Wednesday, September 28, 2011

BIWUG on SharePoint Governance and the past, the present and the future

BIWUG is announcing another session about SharePoint on Thursday October 27th 2011 in the Microsoft Belgium offices.

Agenda

18:00-19:00 Welcome with snacks

19:00-19:15 Introduction

19:15-20:15 SharePoint Governance (Speaker Patrick Sledz): Stop thinking about features features features when talking about governance.

When designing governance for a SharePoint implementation, a lot (not to say all) energy and words go out to technical stuff, SLA's and not to the things that define the business value. And the business value is not only a perfect technically tuned and performant SharePoint farm (if that even exists).

20:15-20:30 Break

20:30-21:00 The past, present and the future of BIWUG

During a seemingly quiet period, a lot has been going on behind the scenes. The result of all this secrecy will be revealed in the second part of the evening.

21:00-21:30 SharePint!

Of course there is also an opportunity to network, socialize and discuss the matter explained the previous hours... therefore SharePint!

Location: Microsoft Belgium Corporate Village - Bayreuth Building, Leonardo Da Vincilaan 3, 1935 Zaventem

Registration is now opened on the BIWUG site www.biwug.be

Sunday, September 25, 2011

Text to speech in windows phone 7

How to use cloud-based Microsoft Translator Service in windows phone 7 to translate text to speech.

In this article I am going to explain how we can take the leverage of cloud to solve the problem for Text to Speech translation. It’s pretty simple to archive such kind of functionality in windows phone 7 using Bing API. Here I will show how we can retrieve a list of languages supported by Microsoft Translator for the Speech API and speak the user’s input text.

First of all we must obtain a valid Bing API AppID, lets follow the below steps.

Step -1 Open below mentioned url to register your application. And follow the instructions to obtain a valid Bing API AppID.

http://www.bing.com/developers/appids.aspx
1

Step-2 Enter required information and obtain a valid Bing API AppID.

2


Once you register your application now we will be moving ahead with the windows phone 7 application developments and invoke the cloud service.

Step-3 Create a windows phone 7 application project.

WP_001

Step-4 To add web reference of the Microsoft Translator Service, we need to add a service reference to Windows Phone project. Right - click the Windows Phone Project in solution explorer, and choose Add Service Reference. Please see below pictures for the same.

http://api.microsofttranslator.com/V2/Soap.svc


WP_002

WP_003

WP_004

Step-5 Now adds a panorama page to windows phone 7 project.

WP_005

Step-6 creates a UI as per application requirement see below xaml code snippet. Here I have added three panorama items.



<Grid x:Name="LayoutRoot">
<controls:Panorama Title="text to speech" Name="panoSpeech" Foreground="Blue" FontFamily="Comic Sans MS">
<!--Panorama item one-->
<controls:PanoramaItem Header="Language(s)" Foreground="Plum" FontFamily="DengXian" FontSize="72">
<StackPanel Orientation="Horizontal">
<StackPanel.Resources>
<DataTemplate x:Key="LanguageTemplate">
<TextBlock Foreground="White" Margin="0,0,0,0" Text="{Binding Name}" />
</DataTemplate>
</StackPanel.Resources>
<ListBox HorizontalAlignment="Left" ItemTemplate="{StaticResource LanguageTemplate}" Margin="20,10,0,20" Name="ListLanguages" Width="441">
</ListBox>
</StackPanel>
</controls:PanoramaItem>

<!--Panorama item two-->
<controls:PanoramaItem Header="Speech" Foreground="Yellow">
<StackPanel Orientation="Vertical" Margin="20,0,0,0">
<TextBox Name="TextToSpeachText" Text="This Pavan Pareta, Microsoft Most Value able proffesional. He has written an application for windows phone 7" TextWrapping="Wrap" Height="350" />
<Button Content="S p e a k" Height="90" Margin="0,30,0,0" Name="btnSpeak" Width="338" Click="btnSpeak_Click" />
</StackPanel>
</controls:PanoramaItem>

<!--Panorama item three-->
<controls:PanoramaItem Header="Speak" Foreground="Violet">
<StackPanel Orientation="Vertical">
<Image Height="auto" Name="image1" Stretch="None" Width="auto" Margin="50 60 80 0" Source="/speak.jpg" />
</StackPanel>
</controls:PanoramaItem>
</controls:Panorama>
</Grid>


Step-7 Fist Panorama item used to develop for retrieving supported speech languages. To retrieve the supported language we need to call web service method “GetLanguagesForSpeakAsync”. The GetLanguagesForSpeak method only returns the language codes, for example, en for English and fr for French etc. see blow UI and code snippet.


WP_006


GetLanguagesForSpeakAsync takes two methods like AppID and object.

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
try
{
FrameworkDispatcher.Update();
var objTranslator = new ServiceReference1.LanguageServiceClient();
objTranslator.GetLanguagesForSpeakCompleted += new EventHandler<GetLanguagesForSpeakCompletedEventArgs>(translator_GetLanguagesForSpeakCompleted);
objTranslator.GetLanguagesForSpeakAsync(AppId, objTranslator);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

void translator_GetLanguagesForSpeakCompleted(object sender, GetLanguagesForSpeakCompletedEventArgs e)
{
var objTranslator = e.UserState as ServiceReference1.LanguageServiceClient;
objTranslator.GetLanguageNamesCompleted += new EventHandler<GetLanguageNamesCompletedEventArgs>(translator_GetLanguageNamesCompleted);
objTranslator.GetLanguageNamesAsync(AppId, "en", e.Result, e.Result);
}

void translator_GetLanguageNamesCompleted(object sender, GetLanguageNamesCompletedEventArgs e)
{
var codes = e.UserState as ObservableCollection<string>;
var names = e.Result;
var languagesData = (from code in codes
let cindex = codes.IndexOf(code)
from name in names
let nindex = names.IndexOf(name)
where cindex == nindex
select new TranslatorLanguage()
{
Name = name,
Code = code
}).ToArray();
this.Dispatcher.BeginInvoke(() =>
{
this.ListLanguages.ItemsSource = languagesData;
});
}

Step-8 Second Panorama item used to develop for speak text using SpeakAsync method takes four string parameters like AppId, SpeechText, SpeechLanguage, format. See below UI and code snippet.


WP_007


private void btnSpeak_Click(object sender, RoutedEventArgs e)
{
var languageCode = "en";
var language = this.ListLanguages.SelectedItem as TranslatorLanguage;
if (language != null)
{
languageCode = language.Code;
}
var objTranslator = new ServiceReference1.LanguageServiceClient();
objTranslator.SpeakCompleted += translator_SpeakCompleted;
objTranslator.SpeakAsync(AppId, this.TextToSpeachText.Text, languageCode, "audio/wav");

panoSpeech.DefaultItem = panoSpeech.Items[(int)2];

}

void translator_SpeakCompleted(object sender, ServiceReference1.SpeakCompletedEventArgs e)
{
var client = new WebClient();
client.OpenReadCompleted += ((s, args) =>
{
SoundEffect se = SoundEffect.FromStream(args.Result);
se.Play();
});
client.OpenReadAsync(new Uri(e.Result));
}


Step-9 Now builds the application and executes it.

WP_008WP_009WP_010

Download source code here

Thank you for your time.