Hi,
while integrating a RadAutoCompleteBox into our application, I noticed a problem when binding to its SearchText and SelectedItem properties:
How we use the AutoCompleteBox:
We use the following XAML markup to create the AutoCompleteBox:
<telerik:RadAutoCompleteBox Grid.Column="0" x:Name="UnitSelectionAutoCompleteBox"
AutoCompleteMode="SuggestAppend"
DisplayMemberPath="UnitNumber"
IsEnabled="{Binding UnitNumberEnabled, Mode=OneWay}"
ItemsSource="{Binding UnitSelectionComponent.SearchResults, Mode=OneWay}"
SearchText="{Binding UnitSelectionComponent.UnitNumberSearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
SelectedItem="{Binding UnitSelectionComponent.SelectedUnit, Mode=TwoWay}"
SelectionMode="Single"
TextSearchMode="Contains"
TextSearchPath="UnitNumber"
WatermarkContent="{StaticResource Loc.UnitNumber}">
</telerik:RadAutoCompleteBox>
Having bound both, the SelectedItem and the SearchText leads to the SearchText binding to break under some circumstances: If UnitSelectionComponent.SelectedUnit is not null when the UI is loaded initially, the SearchText property suddenly contains a hard-coded string instead of the binding we defined. However, there seems to be another required condition I don't know yet since I was not able to reproduce the problem in a simple demo project.
I attached three screenshots of our ui and Snoop:
- binding_working shows the control and its SearchText binding in the default state.
- binding_working2 shows the control and its SearchText binding after selecting an item by first typing into the AutoCompleteBox and then selecting an item from the dropdown.
- binding_broken shows the control and its SearchText binding in the broken state: Instead of the binding, SearchText now only contains a string.
- The issue occurs in two cases:
1. If I open the module with a preselected item (e.g. by opening a saved document),
2. If I use a separate selection module to select an item (the selection module is displayed by temprarily switching the DataContext to show the selection UI. When a new item is selected, we set the SelectedUnit and then the DataContext is switched back to show the module ui again, see RadAutoCompleteBox_LostBinding.gif)
- If the SelectedItem is not bound, the issue does not seem to occur.
- Forcing the ui to be reloaded (e.g. by switching to a different module and then back) makes the binding come back.
Regards
Simon Müller
Hofmann Fördertechnik GmbH