.Net Silverlight 4 – Productivity Power Tools and EF4

12 Comments

Recently, I wanted to do a project in Silverlight 4 using EF4(Entity Framework 4).  When I went to add the ADO.Net Entity Data Model class, I received this error message:

The project’s target framework does not contain Entity Framework runtime assemblies. Please review the target framework information in the project’s property page.

I checked my .Net framework version, and it was .Net 4.0.  So I went searching on Google and found this thread on MSDN.  It seems that there is a problem with VS2010/Productivity Power Tools when using EF4.

If you run across this problem, here are the steps for you to take:

1.  Change the target framework to .Net 3.5.
2.  Rebuild the project.
3.  Change the target framework back to .Net 4.0.
4.  Rebuild the project.

You should now be able to add the EF4 model class to your project.

Another option would be to disable the Productivity Power Tools extension, but if you are like me, the extension is a great extension and I wanted to keep it.

Hope this helps out anybody in the future.

Tags: , , , ,

.Net, Silverlight, Windows Phone 7 WP7 – Using the ToggleSwitch

1 Comment

This will be the first of a number of posts highlighting the new controls that have been added to the WP7 Toolkit.  It’s a really great set of tools that makes life easier for us developers.

Download WP7 Toolkit

So the first control I am going to talk about is the ToggleSwitch control.  It’s a control that resembles a lightswitch and is a nice was of showing an On/Off or True/False setting instead of using a plain checkbox.

So let’s create a Windows Phone 7 project called ToggleSwitchDemo.

Open the Toolbox and find the ToggleSwitch control.  If it’s not listed, right-click on the Toolbox –> Choose Items –> then scroll down until you find the ToggleSwitch control in the list.

Once the control is in the Toolbox, drag it onto the page.  By default, it will look like this….

11-14-2010 10-21-33 AM

Run the application using F5, then click on the ToggleSwitch.  It will change from Off to On.

11-14-2010 10-24-16 AM 11-14-2010 10-24-28 AM

There are a number of options that are available for the text for the ToggleControl.  The Header property will change the heading of the control.  The Content property will set the content of the control(On/Off).

In one of my application, I used the ToggleSwitch to allow the user to turn on/off Ads that I have in the app.  So for me, I changed the Header to “Ads”, and since I default the ToggleSwitch to being On(IsChecked is True), I set the Content to “Ads are enabled.

The ToggleSwitch also allows you to handle when the control is checked and unchecked.  So here is how my ToggleSwitch would look in XAML

<toolkit:ToggleSwitch
    Name="AdsToggleSwitch"
    Header="Ads"
    Content="Ads are enabled"
    Height="111"
    HorizontalAlignment="Left"
    Margin="1,197,0,0"
    VerticalAlignment="Top"
    Width="456"
    IsChecked="True"
    Checked="AdsToggleSwitch_Checked"
    Unchecked="AdsToggleSwitch_Unchecked" />

Then the code for the Checked and Unchecked events…

private void AdsToggleSwitch_Checked(object sender, RoutedEventArgs e)
{
     AdsToggleSwitch.Content = "Ads are enabled";
}

private void AdsToggleSwitch_Unchecked(object sender, RoutedEventArgs e)
{
     AdsToggleSwitch.Content = "Ads are disabled";
}

Now my control would look like this…

11-14-2010 10-41-21 AM 11-14-2010 10-41-30 AM

The ToggleSwitch is a great control that allows your app to keep the “Metro” look and feel that a plain CheckBox wouldn’t allow you to do without custom coding.

Tags: , , ,

.Net, Silverlight, Windows Phone 7 WP7 – Using the Microsoft AdControl

0 Comments

For the Windows Phone 7 platform, Microsoft decided to roll-out it’s own mobile ad service.  This service is Microsoft Advertising PubCenter.  Along with the service, they also added a custom control that we developers can add to our Windows Phone 7 applications.

First, we will need to download the Advertising SDK.  That can be done from here.  After downloading, install it as you would any other .msi, but you will want to note the install directory.  On Windows 7 64-bit, the install directory will be “C:\Program Files (x86)\Microsoft Advertising SDK for Windows Phone 7“.

So first, you will need to go to the PubCenter, create an account(which is free).  Once your account is created, login, then go to the Setup tab.  From here, you will want to register your mobile application and create an application ad unit.  It may take some time for the Ad Unit or application to be approved, so we are allowed to use some testing values for development purposes.

11-13-2010 10-10-17 AM

You will want to note the application ID and the Ad Unit ID.  We will need both of these.

So let’s create a new WP7 project.  I just created a simple project and named it AdControlDemo.

Once the project has been created, open the Toolbox.  We are going to add a new tab for the AdControl.  Right-click somewhere in the Toolbox, then choose Add Tab.

11-14-2010 9-47-51 AM

I gave my tab the name Advertising Control.

11-14-2010 9-46-38 AM

Now right-click in the new Tab area, and click Choose Items.

11-14-2010 9-49-28 AM

When the Choose Items dialog comes up, click the Browse button.

11-14-2010 9-50-48 AM

Navigate to the install directory of the Advertising SDK that was installed.  You will want to add the Microsoft.Advertising.Mobile.UI.dll file.

11-14-2010 9-52-34 AM

You will now see that the AdControl has been added to our list of items.  Now click OK.

11-14-2010 9-54-11 AM

Now the AdControl has been added to our Toolbox.

11-14-2010 9-55-24 AM

Now we are going to simply drag the control onto our screen.  Now open the Properties window, and you will see two properties for the AdUnitId and the ApplicationId.  For testing purposes, you can use “test_client” as the ApplicationId and “TextAd” as the AdUnitId.

So let’s run our application in the emulator by hitting F5, and you will see test ads showing up.

Now, once you setup your own application and ad unit and replaced the test values with your values, you will need to add this code to one of the initialization methods in the App.cs.  I put it at the bottom of the constructor.

Microsoft.Advertising.Mobile.UI.AdControl.TestMode = false;

Without this code, the control will not show on the screen.

You now have advertising in your WP7 application.

Tags: , , , ,