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 377995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:45:01+00:00 2026-05-12T14:45:01+00:00

I have a DataTemplate that will be a templated ListBoxItem, this DataTemplate has a

  • 0

I have a DataTemplate that will be a templated ListBoxItem, this DataTemplate has a
ComboBox in it which when it has focus I want the ListBoxItem that this template
represents to become selected, this looks right to me. but sadly enough it doesn’t work =(

So the real question here is within a DataTemplate is it possible to get or set the value
of the ListBoxItem.IsSelected property via a DataTemplate.Trigger?

<DataTemplate x:Key="myDataTemplate" 
              DataType="{x:Type local:myTemplateItem}">

 <Grid x:Name="_LayoutRoot">
     <ComboBox x:Name="testComboBox" />
 </Grid>

 <DataTemplate.Triggers>
     <Trigger Property="IsFocused" value="true" SourceName="testComboBox">
         <Setter Property="ListBoxItem.IsSelected" Value="true" />
     </Trigger>
 </DataTemplate.Triggers>

</DataTemplate>

<ListBox ItemTemplate="{StaticResource myDataTemplate}" />
  • 1 1 Answer
  • 3 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-05-12T14:45:02+00:00Added an answer on May 12, 2026 at 2:45 pm

    I found a solution for your problem.

    The problem is that when you have a control on your listboxitem, and the control is clicked (like for inputting text or changing the value of a combobox), the ListBoxItem does not get selected.

    this should do the job:

    public class FocusableListBox : ListBox
    {
        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return (item is FocusableListBoxItem);
        }
    
        protected override System.Windows.DependencyObject GetContainerForItemOverride()
        {
            return new FocusableListBoxItem();
        }
    }
    

    –> Use this FocusableListBox in stead of the default ListBox of WPF.

    And use this ListBoxItem:

    public class FocusableListBoxItem : ListBoxItem
    {
        public FocusableListBoxItem()
        {
            GotFocus += new RoutedEventHandler(FocusableListBoxItem_GotFocus);
        }
    
    
        void FocusableListBoxItem_GotFocus(object sender, RoutedEventArgs e)
        {
            object obj = ParentListBox.ItemContainerGenerator.ItemFromContainer(this);
            ParentListBox.SelectedItem = obj;
        }
    
        private ListBox ParentListBox
        {
            get
            {
                return (ItemsControl.ItemsControlFromItemContainer(this) as ListBox);
            }
        }
    
    }
    

    A Treeview does also have this problem, but this solution does not work for a Treeview, ’cause SelectedItem of Treeview is readonly.
    So if you can help me out with the Treeview please 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 10 ComboBox controls that will use the same item template (an Image
I have a ComboBox in WPF which is databound, and has data template which
I have an ItemsControl with a DataTemplate that has been defined. My ItemsControl definition
Scenario: I have a view that has some DataTemplate resources <DataTemplate x:Key=myDragCueTemplate> <Border Background=Blue
I have a Listbox DataTemplate which looks like this <DataTemplate> <StackPanel Margin=0,24,0,24> <StackPanel toolkit:TiltEffect.IsTiltEnabled=true>
I have a DataTemplate which contains a CheckBox and ListBox. When the CheckBox is
Well the problem here is that if you have one DataTemplate for a type
Basically I have a WPF application that will display announcements to the user within
I have a treeview Item as such in a treeview that will have a
I have a listbox template showing an image and three textboxes. You will see

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.