Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8255681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:36:33+00:00 2026-06-08T01:36:33+00:00

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>

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:36:34+00:00Added an answer on June 8, 2026 at 1:36 am

    Try setting the focus on the selected item of your listbox on loaded event like this –

    Loaded += ((sender, e) =>
    {
       ListBoxItem item = myListbox.ItemContainerGenerator.ContainerFromItem(myListbox.SelectedItem) as ListBoxItem;
       item.Focus();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My environment is windows phone 7.1. I have the following code: <ListBox ItemsSource="{Binding Path=Items}">
This is my XAML so far. <ScrollViewer Grid.Column="1" Grid.RowSpan="2"> <ListBox Background="Black" ItemsSource="{Binding Path=ActiveLog}" >
I have a list box in expander: <ListBox ItemsSource={Binding MySource> <ListBox.ItemTemplate> <DataTemplate> <RadioButton Content={Binding
<ListBox Name=DisplayItemListBox> <ListBox.ItemTemplate> <DataTemplate> <ListBoxItem > <StackPanel Orientation=Horizontal> <TextBlock Text={Binding Path=Response} /> <Button Width=50
I have made a CheckedListBox using the following: <ListBox x:Name=lst_checkBoxList ItemsSource={Binding}> <ListBox.ItemTemplate> <DataTemplate> <CheckBox
Here is the XAML: <ListBox ItemsSource={Binding Documents} BorderBrush={x:Null}> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Vertical> <TextBlock Text={Binding
<ListBox BorderThickness=0 x:Name=PendingChatListBox HorizontalContentAlignment=Stretch> <ListBox.ItemTemplate > <DataTemplate> <Button Height=40 Click=OpenChat_click Content={Binding BindsDirectlyToSource=True, Converter={StaticResource cPendingUnreadMessagesConverter}}
I have a WPF Listbox defined in a DataTemplate that has its ItemsSource bound
I have the following constellation in my XAML: <ListBox x:Uid=attributesListBox DataContext={Binding Source={StaticResource EditFeatureWithForeignKeyAttributesViewModel}} ItemsSource={Binding
My xaml ... <ListBox Margin=6,35,6,6 Name=lbLayers SelectionMode=Extended > <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Vertical> <TextBlock Text={Binding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.