I have Listbox
in my WP7 page like this
<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>
My Listbox
is attached to my collection List<SampleData>
Like lstSelectedNumber.itemsource = List<SampleData>;
And for my autocompletebox I want to bind my auto completebox to other collection List so when the user type in my textbox it shows suggestion to user and once user select to any item it adds this item to my other collection List I am facing one problem: how can I bind my list to the autocompletbox which in the listbox so I can do further proceedings?
UPDATE
I am trying to find my listbox control in this way but its returning me 0 always for childs
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);
}
}
}
and in this way I'm calling on my page constructor
SearchVisualTree(this.lstSelectedNumber);