0

Listbox的 WP7 页面中有这样的

   <ListBox Name="lstSelectedNumber" Height="50" MaxHeight="120" VerticalAlignment="Top" Grid.Column="1" SelectionChanged="lstSelectedNumber_SelectionChanged">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="Padding" Value="-15" />
                                <Setter Property="Margin" Value="0"/>
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <toolkit:WrapPanel>
                                </toolkit:WrapPanel>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <toolkit:AutoCompleteBox x:Name="acBox" FilterMode="StartsWith" ValueMemberBinding="{Binding Name,Mode=TwoWay}">
                                    <toolkit:AutoCompleteBox.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <Image Source="{Binding Image}" Stretch="None" Margin="0,0,5,5"/>
                                                <TextBlock Text="{Binding Name}"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </toolkit:AutoCompleteBox.ItemTemplate>
                                </toolkit:AutoCompleteBox>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

Listbox的已附加到我的收藏List<SampleData>

喜欢lstSelectedNumber.itemsource = List<SampleData>;

对于我的自动完成框,我想将我的自动完成框绑定到其他集合列表,因此当用户在我的文本框中键入时,它会向用户显示建议,一旦用户选择任何项目,它就会将此项目添加到我的其他集合列表中我面临一个问题:如何将我的列表绑定到列表框中的自动完成框,以便我可以进行进一步的处理?

更新

我试图以这种方式找到我的列表框控件,但它总是为孩子们返回 0

 private void SearchVisualTree(DependencyObject targetElement)
        {
            var count = VisualTreeHelper.GetChildrenCount(targetElement);
            if (count == 0)
                return;

            for (int i = 0; i < count; i++)
            {
                var child = VisualTreeHelper.GetChild(targetElement, i);
                if (child is AutoCompleteBox)
                {
                    AutoCompleteBox myItems = (AutoCompleteBox)child;

                    if (myItems.Name == "acBox")
                    {
                       // My Logic
                        return;
                    }
                }
                else
                {
                    SearchVisualTree(child);
                }
            }
        }

并以这种方式调用我的页面构造函数

SearchVisualTree(this.lstSelectedNumber);
4

1 回答 1

0
         List<WP7Phone> data = new List<WP7Phone>();

            foreach (lines l in result)
            {
                WP7Phone w7 = new WP7Phone();

                w7.Name = l.line.TrimStart();

                w7.Image = "images/thump.jpg";

                msg.Add(w7);
            }


            this.autoCompleteBox1.ItemsSource = data;


   public class WP7Phone
 {
    public string Name
  {
    get;
    set;
}
public string Image1
{
    get;
    set;
}

}

于 2012-06-05T11:12:31.553 回答