我有一個應用程序,用戶將輸入名稱列表。 (有一些有效名稱的集合。)我不確定最簡單的方法是什麼。用戶友好的方式在Silverlight 4中輸入列表?
一個想法:製作一個文本框。如果文本框失去焦點,並且內容是有效的名稱,請將其添加到列表框中。如果用戶在列表框中選擇一個條目並點擊刪除,請將其刪除。
代碼:
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" />
我是新來的SL,所以我害怕我可能錯過了一些控制或喜好的做事方式。有什麼建議?
謝謝。