0

晚上,我有一个使用 silverlight5 的基本自动完成框。目的是能够通过上面的复选框搜索人员列表并从该列表中删除某些人。在复选框事件中,列表被修改,但这不会反映在自动完成框中。

.xaml:

<StackPanel Orientation="Vertical" x:Name="LayoutRoot" Background="Transparent">
    <sdk:Label Content="Filter By:" FontSize="12" Name="label1" Margin="10,10,10,5" />
    <CheckBox Content="Students" Height="16" Name="checkBox1" Margin="10,5,10,0" Checked="checkBox1_Checked" Unchecked="checkBox1_Checked"/>
    <CheckBox Content="Staff" Height="16" Name="checkBox2" Margin="10,5,10,0" Checked="checkBox2_Checked" Unchecked="checkBox2_Checked"/>
    <CheckBox Content="Guest" Height="16" Name="checkBox3" Margin="10,5,10,10" Checked="checkBox3_Checked" Unchecked="checkBox3_Checked"/>
    <sdk:AutoCompleteBox x:Name="peoplelist"/>
</StackPanel>

后面的代码:

public CustomerFilterControl()
    {
        InitializeComponent();
        //_viewModel.Initialize(); initial loading of context data, populate dropdowns etc
        people.Add("Student 1");
        //.....................add more
        peoplelist.Itemssource = people;
    }

复选框方法:

private void checklist()
    {
        if (checkBox1.IsChecked.Value)
        {
            people.Clear();
            people.Add("Guest 1");
            //.................... add more
            peoplelist.DataContext = people;
    }

大量搜索向我指出了针对早期版本的 sliverlight 的许多工作,但此时我实际上是在绕圈子。

谁能指出我正确的方向来实现这个功能?

4

1 回答 1

1

替换List<string>ObservableCollection<string>

这个泛型引发了 CollectionChangedEvent,因此绑定控件知道它们需要更新。

于 2011-12-21T21:12:18.347 回答