Posts Tagged ‘Silverlight’

.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 Silverlight 4 – Copy/Paste From Clipboard

0 Comments

In this tutorial, I will show how you can use Silverlight 4 to get access to the client clipboard. Silverlight 3 had limited clipboard access, but Microsoft implemented more complete access to the clipboard.

For security purposes, access to the clipboard is only allowed through a user-initialed event. For example, you couldn’t have a timer running in the background to constantly get text from the clipboard.

For first, let’s create a Silverlight 4 application and name it SL4ClipboardAccess. Then Click OK on the next popup.

10-28-2010 10-05-33 AM

I added some controls to the page..

<Grid x:Name="LayoutRoot" Background="White">

    <TextBox
        Name="CopyTextTextBox"
        Height="23"
        HorizontalAlignment="Left"
        Margin="132,36,0,0"
        VerticalAlignment="Top"
        Width="174" />

    <TextBlock
        Name="textBlock1"
        Text="Text To Copy:"
        Height="23"
        HorizontalAlignment="Left"
        Margin="47,40,0,0"
        VerticalAlignment="Top" />

    <Button
        Name="CopyToClipboardButton"
        Content="Copy To Clipboard"
        Click="CopyToClipboardButton_Click"
        Height="39"
        HorizontalAlignment="Left"
        Margin="144,81,0,0"
        VerticalAlignment="Top"
        Width="145"  />

    <Button
        Click="PasteToTextBoxButton_Click"
        Name="PasteToTextBoxButton"
        Content="Paste To Textbox"
        Height="39"
        HorizontalAlignment="Left"
        Margin="144,147,0,0"
        VerticalAlignment="Top"
        Width="145"  />

    <TextBox
        Name="PasteTextTextBox"
        Height="23"
        HorizontalAlignment="Left"
        Margin="132,209,0,0"
        VerticalAlignment="Top"
        Width="174" />

    <TextBlock
        Name="textBlock2"
        Text="Text From Clipboard:"
        Height="23"
        HorizontalAlignment="Left"
        Margin="8,209,0,0"
        VerticalAlignment="Top" />

</Grid>

Which look like this…

10-28-2010 10-19-03 AM

Now, the Click Event for the CopyToClipboard Button would look like this…

private void CopyToClipboardButton_Click(object sender, RoutedEventArgs e)
{
    string textToCopy = CopyTextTextBox.Text;

    try
    {
         Clipboard.SetText(textToCopy);
    }
    catch (SecurityException se)
    {
        MessageBox.Show(se.Message);
    }
}

and the Click Event for the PasteToTextBox Button would be this..

private void PasteToTextBoxButton_Click(object sender, RoutedEventArgs e)
{
    string textFromClipboard = string.Empty;

    try
    {
         textFromClipboard = Clipboard.GetText();
    }
    catch (SecurityException se)
    {
         MessageBox.Show(se.Message);
    }

    PasteTextTextBox.Text = textFromClipboard;
}

Now run the application and type into the Text To Copy textbox. When you click the Copy To Clipboard button, you will be prompted for permission for access to the clipboard.

10-28-2010 10-15-52 AM

After allowing access, click the Paste To TextBox button, and the text will now be in the other textbox.

Very simple tutorial for a very powerful feature.

Tags: , , ,

.Net, Silverlight Silverlight 4 – Sample Data with Blend 4

2 Comments

In a previous tutorial, I showed how to do a custom Item Template for a ListBox. However, one of the painstaking parts of that was having to create the class and the code to populate the ListBox with actual data. Also, even though I was populating the ListBox, I still simply saw blank controls during design-time.

This is where Sample Data comes in. Not only can you quickly create sample data for a control, you can drag and drop it onto the control, and the ItemTemplate will be created for you(which you can still edit). And the biggest plus to using Sample Data?….the data can be view at DESIGN-TIME.

So first, let’s create a Silverlight project in Blend. I named mine SampleDataProject.

10-24-2010 9-43-51 AM

Next, we will put a ListBox on our page, and give it a Height of 200 and a Width of 250.

<ListBox
	Margin="178,128,212,152"
	Width="250"
	Height="200"/>

Now that we have the ListBox on the page, we can create our Sample Data. Click on the Data window, then on the “Create sample data” button, then choose “New Sample Data…”

10-24-2010 9-47-27 AM

We are going to name it PersonDataSource.

10-24-2010 9-49-06 AM

A couple of things to note on this screen. You will see two radio buttons: Project, and This document. If you choose Project, it will make the sample data available to any control in the project. If you choose This document, then the sample data will only be available to this page.

You will also see a checkbox on this screen saying “Enable sample data when application is running”. This allows you to use the sample data in design time, but use another data source during runtime. Uncheck this box if you want to use a different data source at runtime. Since we want our sample data for design time and runtime, we will leave it checked.

After creating the sample data, the Data window will now show our data in a treeview type layout. By default, it will add two properties for us.

Let’s change the first property by double clicking it and giving it the name FullName.

Let’s change the second property to Age. By default, this property is set to a boolean type. Since our age is not a boolean value, we need to change that to a numeric format. Click on the “Change property type” button on the far right of the property line. You will see a dropdown with different types. Choose “Number”. We will leave it’s length at 2.

10-24-2010 9-55-17 AM

Now that we have the properties setup, we need to add some actual data. Click on the “Edit sample values” button…

10-24-2010 9-58-49 AM

You will now see a window with a number of rows and data. At the bottom, you can determine how many rows you want to show. We are going to change this to 3. We are going to add some data to those rows, then click OK.

10-24-2010 10-00-41 AM

Now that we have our sample data setup, let’s simply drag and drop the “Collection” from the Data window onto the ListBox. The ListBox will create it’s own ItemTemplate to display the data.

That’s all you have to do. As you can see, we now have data in our ListBox while designing it…

10-24-2010 10-11-16 AM

You can look at my other tutorial on how to edit the created ItemTemplate to show the data different ways.

To me, this is one of the best features of Blend. Being able to see how a collection control will look at design time will speed up the development process. No longer will you have to continuously run the application to see if you have the layout correct.

Tags: , , , ,