Listbox in a DataTemplate
<ListBox
ItemsSource="{Binding Path=(Duties:IPicker.Choices)}"
SelectedValue="{Binding Path=(Duties:IPicker.Selection),
ValidatesOnDataErrors=True,
UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel MaxWidth="{DynamicResource ListWidth}" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
SelectedValue binding works fully Only if dont move focus when usercontrol loads
I want to focus the first element in the usercontrol when i navigate back to the control (using Prism navigation), which happens to be the listbox.
But when I add the following line then every time i navigate back, the selection is reset to the first item, seen as a blue highlight - the selection does not stay at the previously selected item.
Loaded += (sender, e) =>
control.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
Without the line everything works, except the listbox does not have keyboard focus (gray highlight of the previously selected listbox item rather than blue highlight).
Also, the problem only happens if i focused on another listbox before navigating forward i.e. there are two lisboxes and if i stay on the first listbox before navigating forward then the correct selection is retained even with the movefocus?