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开发者_如何学C,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.
Is this for a batch entry, where an opertor will sit and enter a list of names from some source like a paper list or something?
If so, then I would imagine the data entry should be as slick as possible. These operators that do this type of thing day in and day out are usually lightning fast an accurate.
So one option would be that once the operator hits the Enter key on the textbox, the content is moved to the list, the textbox cleared and ready for the next entry. That way the operator never leaves the keyboard. Just type name, hit Enter, type next name etc.
If the operator mistyped a name the operator can press tab to navigate to the list which will immediately select the last name entered. The operator can either press Del key to delete the entry or Ins to edit, edit will remove the name from the list put it back in the textbox and set focus to the textbox so that the operator can edit the name.
Out of the box I do not think there are any special controls that will handle this keyboard navigation for you. You will need to handle the iteraction youself, of course in SL this is not incredibly painful.
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.
精彩评论