Short story: The ListBox inside the focus area does not allow you to select an item.
Long story:
I am trying to create a context dependent widget for data entry. I have a main panel with several fields. Below, I have a panel with FocusManager.FocusScope="True"
. This panel will be filled with the corresponding widgets for the field that is currently focused. For example, when you select a date field, a calendar will be displayed at the bottom of the screen.
I have several controls that require the user to select one of many values ββfrom the list. I put the ListBox in the focus area, but I cannot select any items. When something is selected (programmatically) and you click on the ListBox, it selects everything.
I checked several events and did not collect MouseDown events, but it collects MouseMove events. It starts GotFocus whenever I click on an element, but it never starts LostFocus. I'm not sure what that means, but I hope this can help someone who reads it.
Here is the code I'm using to display a context sensitive widget. I have the following XAML in my window:
<Grid x:Name="EntryWidget" FocusManager.IsFocusScope="True"> <Grid.Resources> <ListBox x:Key="List" ItemsSource="{Binding}" /> </Grid.Resources> </Grid>
I use the Window.GotFocus routed event to update the widget to the corresponding control, for example:
private void Window_GotFocus(object sender, RoutedEventArgs e) { FrameworkElement focus = (FrameworkElement)FocusManager.GetFocusedElement(this); EntryWidget.Children.Clear();
So:
Is there a way to get ListBox to work in focus area?
Or is there another list control that works better inside the focus area?
Or am I using the wrong approach using focus areas? My requirements: The user should be able to select an item from the scroll list, which enters a value in the current field. The current field should not lose focus.
Kendall frey
source share