Thursday, 2 May 2013

Windows Store App - Online Advertising in your app


1. Download the Microsoft Advertising SDK for Windows 8
2. Add references in your project

3. Add refernce in your xaml
xmlns:UI="using:Microsoft.Advertising.WinRT.UI"
4. Add the control in your xaml, make sure you give the correct ApplicationID and AdUnitID created at the pubCentre against your hotmail account. give the correct width and height.
<UI:AdControl Visibility="Visible"  Width="500" Height="65"
                    x:Name="AdCntrl"
                  IsAutoRefreshEnabled="True"   ApplicationId="d25517cb-12d4-4699-8bdc-52040c712cab"  AdUnitId="10042999"
                  />
5. Build the project and run your app. It works!!!

Windows Store App - Google Analytics

1. Download the library from http://w8ga.codeplex.com/releases/view/98265
2. Add reference to it from your app
3. Add the project DT.GoogleAnalytics.Metro in your project as in screen shot


4. Add using DT.GoogleAnalytics.Metro; in the required page in ur app
5. Add the following 2 lines to ur App.xaml, give the exact WebPropertyId - This is very important.

6. Follow the steps  from 3 to 8 in https://w8ga.codeplex.com/wikipage?title=Howto  if u wish to add the GA ref in ur App.xaml.cs 
7. if u want google analytics to work in other pages, add the code below : 

var ver = Windows.ApplicationModel.Package.Current.Id.Version;
var appVersion = ver.Major + "." + ver.Minor + "." + ver.Build + "." + ver.Revision;
//appVersion gives you the version of ur app
string pageUrl = "GAME_SS_" + appVersion.ToString() + "_" + CultureInfo.CurrentCulture.Name + "Win8";
AnalyticsHelper.TrackPageView(pageUrl);
You can give whatever string u want in pageUrl which lets u identify the page of ur app and this url will be displayed in the Google Analytics page.


Windows Store App - Audio Playback across all pages


Add the following in MainPage.xaml

<Frame x:Name="frame1" />
        <MediaElement Name="media"
              AudioCategory="BackgroundCapableMedia"
              Source="/Sounds/bgmusic_v9.mp3" Loaded="OnMediaLoaded"/>

Add the following in MainPage.xaml.cs

private void OnMediaLoaded(object sender, RoutedEventArgs e)
    {
            if (App.appVariables.GlobalAudioElement == null)
              App.appVariables.GlobalAudioElement = sender as MediaElement;
    }



Add a static variable GlobalAudioElement.
public  MediaElement GlobalAudioElement = null;



Add the code in the required pages in ur app

        /// <summary>
        /// Mute the sound and displays the unmute button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnMuteClick(object sender, RoutedEventArgs e)
        {
            App.appVariables.Mute = true;
            App.appVariables.GlobalAudioElement.Pause();
            btnMute.Visibility = Visibility.Collapsed;
            btnUnMute.Visibility = Visibility.Visible;
        }
        /// <summary>
        /// Unmute the sound and displays the mute button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnUnMuteClick(object sender, RoutedEventArgs e)
        {
            App.appVariables.Mute = false;
            App.appVariables.GlobalAudioElement.Play();
            btnMute.Visibility = Visibility.Visible;
            btnUnMute.Visibility = Visibility.Collapsed;
        }


Friday, 7 December 2012

Intentionally left blank.The document root element is not supported by the visual designer.


if ur xaml is not blank and has controls
close VS , open VS and build the whole solution.
the error wil vanish :)

"Invalid index. (Exception from HRESULT: 0x8002000B (DISP_E_BADINDEX))"


That is because the parameters (or parameters names) you set in your code are different from defined parameters in your report

Wednesday, 14 November 2012

Unable to find the report in the manifest resources. Please build the project, and try again

This error occurred to us when we were trying to run a crystal report in Silverlight 4.
The report was put in a folder with name 'MTS Reports'.
When the space in the folder name was removed and renamed as 'MTS_Reports' in the .cs file of the added crystal report and after we rebuilt the application, the error was resolved.

Hope This Helps. 

|,|| and &,&& in C#

The && and || operators in C# work very similarly to their And and Or counterparts (& and | in C#).
The difference is that with these operators the second expression is never evaluated
when the first one already determines the outcome of the entire expression
eg: if (userName == “Administrator” && GetNumberOfRecordsFromDatabase() > 0)

Now, GetNumberOfRecordsFromDatabase() will only be executed when the current user is
Administrator. The code will be ignored for all other users, resulting in increased performance for them.

&& in C# is equivalent to AndAlso in C#
|| in C# is equivalent to OrElse in C#

&& and || are not advisable if each and every expression is to be evaluated.

&&' and '||' are what's called "short-circuiting" logical operators.

In the case of &&, if the first operand is false, then it doesn't bother evaluating the second operand, because the whole expression is certain to be false.

In the case of ||, if the first operand is true, then it doesn't bother evaluating the second operand, because the whole expression is certain to be true.

'&' and '|' can also be used as logical operators though it's more common for them to be used as bitwise operators. When they're used as logical operators, both operands are always evaluated.