0

I have an autocompletebox with these databindings:

<sdk:AutoCompleteBox Height="23" HorizontalAlignment="Left" Margin="80,21,0,0" Name="comboBox_clients" VerticalAlignment="Top" Width="171" ItemsSource="{Binding}" IsTextCompletionEnabled="True" IsDropDownOpen="True" ValueMemberPath="client_code">
    <sdk:AutoCompleteBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding client_code}" Name="left" Width="70" />
                <TextBlock Text="{Binding client_name}" Name="right" Width="250" />
            </StackPanel>
        </DataTemplate>
    </sdk:AutoCompleteBox.ItemTemplate>
</sdk:AutoCompleteBox>

It works like I want, but it appears on a form that gets loaded a lot, and because the autocompletebox has a few thousand items, it takes two or three seconds at initial load to get all of the strings indexed/in order/whatever once I bind it with the appropriate observablecollection.

Instead I want to keep the autocompletebox object as a global so the few second indexing time only happens on the first load, and then during subsequent openings of the window, the autocompletebox on the form can just be set to the global one. How would I duplicate this databinding structure in code?

J. Steen
  • 15,470
  • 15
  • 56
  • 63
cost
  • 4,420
  • 8
  • 48
  • 80

1 Answers1

1

Firstly create a AutoComplete and set its DataTemplate (The below links lead you the way).

You can't get an instance of a DataTemplate codebehind side,but...

https://stackoverflow.com/a/7101581/413032

https://stackoverflow.com/a/72158/413032

But if I were you in spite of of creating datatemplate in codebehind creating a small resource and reaching it from code behind make things easier.

Community
  • 1
  • 1
Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83