I implemented a PRO SDK SearchTextBox however it works pretty slow. I read from a CSV file and create an object type Observable Collection and dump that into SuggestionSource then filter the results as SearchBox text change. Do you have any idea what I am doing wrong?
XAML :
<!-- Inserting inside user control -->
xmlns:controls="clr-namespace:ArcGIS.Desktop.Framework.Controls;assembly=ArcGIS.Desktop.Framework"
<!-- Inserting inside a stack panel-->
<controls:SearchTextBox x:Name="SearchLayersBox" Height="23" Margin="5,5,10,10" VerticalAlignment="Top" InfoText="Search" SearchMode="Auto" ShowHistory="True" Search="SearchTextBox_Search" Initialized="SearchLayersBox_Initialized" TextChanged="SearchLayersBox_TextChanged" SuggestionListMax="15" />
C#
public void LayersListSearchBox()
{
LayerDict.Clear();
DataListBoxSource.Clear();
var path = @"\\nrdsmnt6\mine maps\DMP_Database\Layer_Properties_spc_CSV.csv";
using (TextFieldParser csvParser = new TextFieldParser(path))
{
csvParser.SetDelimiters(new string[] { "*%&" });
csvParser.HasFieldsEnclosedInQuotes = false;
//Skip the row with the column names
csvParser.ReadLine();
while (!csvParser.EndOfData)
{
string[] fields = csvParser.ReadFields();
string LayerDisplayName = fields[3].Substring(1);
SearchSuggestCollection.Add(LayerDisplayName);
}
}
SearchLayersBox.SuggestionSource = SearchSuggestCollection;
}
private void SearchLayersBox_TextChanged(object sender, TextChangedEventArgs e)
{
string searchString = SearchLayersBox.Text;
ObservableCollection<object> filteredCollection = new ObservableCollection<object>(from objectL in SearchSuggestCollection where objectL.ToString().Contains(searchString) select objectL);
SearchLayersBox.SuggestionSource = filteredCollection;
}
private void SearchLayersBox_Initialized(object sender, EventArgs e)
{
LayersListSearchBox();
}
Solved! Go to Solution.
The major problem was assignment of the collection right after initialization and assigning again when it is updated. One assignment was enough as far as it is Observable Collection.
SearchLayersBox.SuggestionSource = SearchSuggestCollection;
Then I also add a requirement to enter 3 characters before firing up the autosuggestions. However, this is not proper MVVM model. If somebody can explain a proper structure for MVVM model for ArcGIS Pro SDK framework, it would be very useful.
The major problem was assignment of the collection right after initialization and assigning again when it is updated. One assignment was enough as far as it is Observable Collection.
SearchLayersBox.SuggestionSource = SearchSuggestCollection;
Then I also add a requirement to enter 3 characters before firing up the autosuggestions. However, this is not proper MVVM model. If somebody can explain a proper structure for MVVM model for ArcGIS Pro SDK framework, it would be very useful.