EzDevInfo.com

silverlight interview questions

Top silverlight frequently asked interview questions

Getting Started with Windows Phone 7

This is a community wiki list of Windows Phone 7 resources. Feel free to edit/add/etc.

When posting, please use the friendly format of
[Actual Name of resource with a link]
not
[some long URL with no meaning unless I click on it]

General Information
App hub - central place for windows phone/xbox development tools/tutorials/info
Windows Phone Home
Windows Phone Team blog
Programming Guide
Class Library Reference
Microsoft Patterns & Practices: Windows Phone 7 Developer Guide

Blogs
Den by default: Windows Phone 7
.NET Zone: Windows Phone 7
Shawn Wildermuth: Windows Phone 7
Jeff Blankenburg: 31 Days of Windows Phone

Articles
Building a Windows Phone 7 Puzzle Game
Windows Phone 7 View Model Style Video Player
Perst - a database for Windows Phone 7 Silverlight
Understanding the Windows Phone Application Execution Model, Tombstoning, Launcher and Choosers:
(part1) (part2) (part3)
Performance Tips when creating WP7 apps
Windows Phone 7 Live Tile Schedules – How to execute instant Live Tile updates
Tips to get your Application in the Windows Phone 7 Marketplace ASAP
Checking for Network connectivity in Windows Phone 7 SDK
Windows Phone 7.1: a Quick Start
A Simple Multi-Page Windows Phone 7 Phonegap Example

Books
Programming Windows Phone 7
Professional Windows Phone 7 Application Development
Pro Windows Phone 7 Development
Beginning Windows Phone 7 Development
Learning Windows Phone Programming
Windows Phone 7 Game Development
Windows Phone 7 Application Development
101 Windows Phone 7 Apps, Volume I: Developing Apps 1-50
101 Windows Phone 7 Apps, Volume II: Developing Apps 51-101 (Fall 2011)

Podcasts
Charlie Kindel on Windows Phone 7
Daniel Egan talks Windows Phone 7 Live at Launch
Windows Phone 7 Series - The Developer Experience with Charlie Kindel
Charles Petzold on Windows Phone 7 Series

Videos
Windows Phone 7 Jump Start sessions
Colin Melia on Windows Phone 7
Channel9 Content for WIndows Phone

Developer Tools
8 Must-Have Tools for Windows Phone 7 Development
Windows Phone Developer Tools RTW
EQATEC Profiler for Windows Phone 7
BugSense, bug tracking for Windows Phone 7

Frameworks
OpenNETCF.IoC Framework
Autofac for WP7
Microsoft Silverlight Analytics Framework
MVVM Light Toolkit
Columbus: Windows Phone 7 MVC framework
Windows Phone MVP
Caliburn.Micro - MVVM framework strongly based on conventions


Source: (StackOverflow)

TextBox.TextChanged event firing twice on Windows Phone 7 emulator

I have a very simple test app just to play around with Windows Phone 7. I've just added a TextBox and a TextBlock to the standard UI template. The only custom code is the following:

public partial class MainPage : PhoneApplicationPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private int counter = 0;

    private void TextBoxChanged(object sender, TextChangedEventArgs e)
    {
        textBlock1.Text += "Text changed " + (counter++) + "\r\n";
    }
}

The TextBox.TextChanged event is wired up to TextBoxChanged in the XAML:

<TextBox Height="72" HorizontalAlignment="Left" Margin="6,37,0,0"
         Name="textBox1" Text="" VerticalAlignment="Top"
         Width="460" TextChanged="TextBoxChanged" />

However, every time I press a key when running in the emulator (either the on-screen keyboard or the physical one, having pressed Pause to enable the latter) it increments the counter twice, displaying two lines in the TextBlock. Everything I've tried shows that the event is genuinely firing twice, and I've no idea why. I've verified that it's only being subscribed once - if I unsubscribe in the MainPage constructor, nothing happens at all (to the text block) when the text changes.

I've tried the equivalent code in a regular Silverlight app, and it didn't occur there. I don't have a physical phone to reproduce this with at the moment. I haven't found any record of this being a known problem in the Windows Phone 7.

Can anyone explain what I'm doing wrong, or should I report this as a bug?

EDIT: To reduce the possibility of this being down to having two text controls, I've tried removing the TextBlock completely, and changing the TextBoxChanged method to just increment counter. I've then run in the emulator, typed 10 letters and then put a breakpoint on the counter++; line (just to get rid of any possibility that breaking into the debugger is causing issues) - and it shows counter as 20.

EDIT: I've now asked in the Windows Phone 7 forum... we'll see what happens.


Source: (StackOverflow)

Advertisements

Silverlight: stretching to remaining space in StackPanel

I have a vertical StackPanel with two elements: a Button and a ListBox. How can I have the ListBox stretch to the remaining page height?

<StackPanel Height="Auto" Width="Auto">
    <Button Height="30" Width="100" Content="Get Content" x:Name="GetContent"/>
    <ListBox Height="Auto" Width="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</StackPanel>

Note that I got this to work using a Grid container:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Button Width="100" Height="30" Content="Get Content" Click="OnGetContent" Grid.Row="0" Grid.Column="0"/>
    <data:DataGrid x:Name="MyContent" Margin="0,5" Grid.Row="1" Grid.Column="0"/>
</Grid>

Source: (StackOverflow)

Silverlight vs Flex

My company develops several types of applications. A lot of our business comes from doing multimedia-type apps, typically done in Flash. However, now that side of the house is starting to migrate towards doing Flex development.

Most of our other development is done using .NET. I'm trying to make a push towards doing Silverlight development instead, since it would take better advantage of the .NET developers on staff. I prefer the Silverlight platform over the Flex platform for the simple fact that Silverlight is all .NET code. We have more .NET developers on staff than Flash/Flex developers, and most of our Flash/Flex developers are graphic artists (not real programmers). Only reason they push towards Flex right now is because it seems like the logical step from Flash.

I've done development using both, and I honestly believe Silverlight is easier to work with. But I'm trying to convince people who are only Flash developers.

So here's my question: If I'm going to go into a meeting to praise Silverlight, why would a company want to go with Silverlight instead of Flex? Other than the obvious "not everyone has Silverlight", what are the pros and cons for each?


Source: (StackOverflow)

Cannot install silverlight 4 tools on visual studio 2010 sp1

I've installed Visual Studio 2010 (fresh install), then applied the SP1. Now I've tried to install the silverlight 4 tools, but i'm getting a strange error message :

"Visual Studio 2010 or Visual Web Developer Express 2010 or Visual Phone Developer Express 2010 that matches the language version of Silverlight Tools 4 must be installed before installation of Silverlight Tools can continue. Silverlight Tools is available in other languages at http://go.microsoft.com/fwlink/?LinkId=177432.

The Visual Web Developer feature for Visual Studio 2010 must be installed before installation can continue."

I've triple checked and there's no language conflict. Browsing the web, some guys have the same error, but there are some MSDN posts that say that with SP1 you don't need to install silverlight tools because they're already bundled with SP1, but that's not the case here, I don't have any project templates in VS for silverlight, and the tools aren't installed. Any ideas??


Source: (StackOverflow)

What are these numbers on the right side of my Windows Phone Silverlight app?

I've got a Windows Phone Silverlight app, and there are some numbers to the right when I run the emulator:

enter image description here

What do they mean, and how can I hide them?


Source: (StackOverflow)

What is so evil about a Flash based website?

I have the feeling that Flash-based ( or Silverlight-based) websites are generally frowned upon, except when you are creating games or multimedia-content rich applications. Why this is so?


Source: (StackOverflow)

How do I space out the child elements of a StackPanel?

Given a StackPanel:

<StackPanel>
  <TextBox Height="30">Apple</TextBox>
  <TextBox Height="80">Banana</TextBox>
  <TextBox Height="120">Cherry</TextBox>
</StackPanel>

What's the best way to space out the child elements so that there are equally-sized gaps between them, even though the child elements themselves are of different sizes? Can it be done without setting properties on each of the individual children?


Source: (StackOverflow)

WPF vs Silverlight [duplicate]

Possible Duplicate:
What is the difference between WPF and Silverlight application?

What are the exact differences between WPF and Silverlight?


Source: (StackOverflow)

Passing an enum value as command parameter from XAML

I want to pass an enum value as command parameter in WPF, using something like this:

<Button 
    x:Name="uxSearchButton" 
    Command="{Binding Path=SearchMembersCommand}" 
    CommandParameter="SearchPageType.First"
    Content="Search">
</Button>

SearchPageType is an enum and this is to know from which button search command is invoked.

Is this possible in WPF, or how can you pass an enum value as command parameter?


Source: (StackOverflow)

How to automatically select all text on focus in WPF TextBox?

If I call SelectAll from a GotFocus event handler, it doesn't work with the mouse - the selection disappears as soon as mouse is released.

EDIT: People are liking Donnelle's answer, I'll try to explain why I did not like it as much as the accepted answer.

  • It is more complex, while the accepted answer does the same thing in a simpler way.
  • The usability of accepted answer is better. When you click in the middle of the text, text gets unselected when you release the mouse allowing you to start editing instantly, and if you still want to select all, just press the button again and this time it will not unselect on release. Following Donelle's recipe, if I click in the middle of text, I have to click second time to be able to edit. If I click somewhere within the text versus outside of the text, this most probably means I want to start editing instead of overwriting everything.

Source: (StackOverflow)

Difference between SelectedItem, SelectedValue and SelectedValuePath

What is the difference betweeen the following:

All these dependency properties are defined in Selector class. I often confuse SelectedItem with SelectedValue , and SelectedValue with SelectedValuePath.

I would like to know the difference between them, and also when do we use them, especially SelectedValue and SelectedValuePath. Please explain their use with some simple examples.


Source: (StackOverflow)

Binding ComboBoxes to enums... in Silverlight!

So, the web, and StackOverflow, have plenty of nice answers for how to bind a combobox to an enum property in WPF. But Silverlight is missing all of the features that make this possible :(. For example:

  1. You can't use a generic EnumDisplayer-style IValueConverter that accepts a type parameter, since Silverlight doesn't support x:Type.
  2. You can't use ObjectDataProvider, like in this approach, since it doesn't exist in Silverlight.
  3. You can't use a custom markup extension like in the comments on the link from #2, since markup extensions don't exist in Silverlight.
  4. You can't do a version of #1 using generics instead of Type properties of the object, since generics aren't supported in XAML (and the hacks to make them work all depend on markup extensions, not supported in Silverlight).

Massive fail!

As I see it, the only way to make this work is to either

  1. Cheat and bind to a string property in my ViewModel, whose setter/getter does the conversion, loading values into the ComboBox using code-behind in the View.
  2. Make a custom IValueConverter for every enum I want to bind to.

Are there any alternatives that are more generic, i.e. don't involve writing the same code over and over for every enum I want? I suppose I could do solution #2 using a generic class accepting the enum as a type parameter, and then create new classes for every enum I want that are simply

class MyEnumConverter : GenericEnumConverter<MyEnum> {}

What are your thoughts, guys?


Source: (StackOverflow)

Error HRESULT E_FAIL has been returned from a call to a COM component

In Silverlight 4 app; what does this error mean?:

"Error HRESULT E_FAIL has been returned from a call to a COM component."

It's a very generic error. The VS debugger doesn't point to the exact location of the error when debugging.


Source: (StackOverflow)

Why dependency properties?

Why did Microsoft go the route of making dependency properties and dependency objects instead of using reflection and maybe attributes?


Source: (StackOverflow)