tags:

views:

23

answers:

2

I have an app where users will enter lists of names. (There is some collection of valid names.) I'm not sure what the most user-friendly way to do this is.

One idea: Make a text box. If the text box loses focus, and the contents are a valid name, add it to a list box. If the user selects an entry in the list box and hits delete, remove it.

The code:

MainPage.xaml.cs:

    private void WhoOwesInput_LostFocus(object sender, RoutedEventArgs e)
    {
        if (people.Contains(WhoOwesInput.Text))
        {
            WhoOwesListBox.Items.Add(WhoOwesInput.Text);
            WhoOwesInput.Text = String.Empty;
        }
    }

    private void WhoOwesListBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Delete || e.Key == Key.Back)
        {
            WhoOwesListBox.Items.Remove(WhoOwesListBox.SelectedItem);
        }
    }

MainPage.xaml:

<sdk:AutoCompleteBox Height="23" HorizontalAlignment="Left" Margin="337,205,0,0" Name="WhoOwesInput" VerticalAlignment="Top" Width="74" ValueMemberBinding="{Binding}" LostFocus="WhoOwesInput_LostFocus" />
<ListBox Height="100" HorizontalAlignment="Left" Margin="337,232,0,0" Name="WhoOwesListBox" VerticalAlignment="Top" Width="74" KeyDown="WhoOwesListBox_KeyDown" />

I'm new to SL, so I'm afraid I may be missing out on some controls or preferred way of doing things. Any advice?

Thanks.

A: 
Chris Taylor
A: 

First of all do the same thing for the Enter key as aforementioned. However, if you come up with much more information that you want your users to data-entry you should consider a little better design.

Silverlight has a great mechanism of data binding, speaking of which, it is about databinding dependency properties of controls (ItemSource of a listbox) to clr properties on a separate class which is the DataContext of your xaml file. What I described in this one liner is one part of the famous Presentation - Model pattern or as Microsoft calls it. MVVM. So, as you are new to Silverlight, learn about these concepts which will make your life easier.

For the time being, you could do what Chris said above.

Aggelos Mpimpoudis