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

  • Home
  • SEARCH
  • 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 699643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:24:32+00:00 2026-05-14T03:24:32+00:00

I created a custom ComboBox as follows: (note, code is not correct but you

  • 0

I created a custom ComboBox as follows: (note, code is not correct but you should get the general idea.) The ComboBox contains 2 dependency properties which matter: TitleText and DescriptionText.

<Grid>
  <TextBlock x:Name="Title"/>
  <Grid x:Name="CBG">
    <ToggleButton/>
    <ContentPresenter/>
    <Popup/>
  </Grid>
</Grid>

I want to use this ComboBox to display a wide range of options. I created a class called Setting which inherits from DependencyObject to create usable items, I created a DataTemplate to bind the contents of this Settings object to my ComboBox and created a UserControl which contains an ItemsControl which has as a template my previously mentioned DataTemplate. I can fill it with Setting objects.

<DataTemplate x:Key="myDataTemplate">
  <ComboBox TitleText="{Binding Title}" DescriptionText="{Binding DescriptionText}"/>
</DataTemplate>

<UserControl>
  <Grid>
    <StackPanel Grid.Column="0">
      <ItemsControl Template="{StaticResource myDataTemplate}">
        <Item>
          <Setting Title="Foo" Description="Bar">
            <Option>Yes</Option><Option>No</Option>
          </Setting>
        </Item>
      </ItemsControl>
    </StackPanel>
    <StackPanel Grid.Column="1">
      <TextBlock x:Name="Description"/>
    </StackPanel>
  </Grid>
</UserControl>

I would like to have the DescriptionText of the selected ComboBox (selected by either the IsFocus of the ComboBox control or the IsOpen property of the popup) to be placed in the Description TextBlock in my UserControl.

One way I managed to achieve this was replacing my ItemsControl by a ListBox but this caused several issues: it always showed a scrollbar even though I disabled it, it wouldn’t catch focus when my popup was open but only when I explicitly selected the item in my ListBox, when I enabled the OverridesDefaultStyle property the contents of the ListBox wouldn’t show up at all, I had to re-theme the ListBox control to match my UserControl layout…

What’s the best and easiest way to get my DescriptionText to show up without using a ListBox or creating a custom Selector control (as that had the same effect as a ListBox)?

The goal at the end is to loop through all the items (maybe get them into an ObservableCollection or some sort and to save them into my settings file.

  • 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-05-14T03:24:33+00:00Added an answer on May 14, 2026 at 3:24 am

    I think I know what you are trying to do. Here is a possible solution.

    You should use a ListBox (or anything deriving from Selector control) in order to use the SelectedItem property.

    <UserControl>
      <Grid>
        <StackPanel Grid.Column="0">
          <ListBox x:Name="SettingListBox" Template="{StaticResource myDataTemplate}">
            <Item>
              <Setting Title="Foo" Description="Bar">
                <Option>Yes</Option><Option>No</Option>
              </Setting>
            </Item>
          </ListBox >
        </StackPanel>
        <StackPanel Grid.Column="1">
          <TextBlock x:Name="Description"
              Text="{Binding SelectedItem.Description, ElementName=SettingListBox}"/>
        </StackPanel>
      </Grid>
    </UserControl>
    

    To solve the problem where your ListBox does not focus on the item when you open the ComboBox drop-down menu, I have an attached property that will fix that for you.

    public class ListBoxHelper
    {
        #region Dependency Property
    
        public static bool GetCanFocusParent(DependencyObject obj)
        {
            return (bool)obj.GetValue(CanFocusParentProperty);
        }
    
        public static void SetCanFocusParent(DependencyObject obj, bool value)
        {
            obj.SetValue(CanFocusParentProperty, value);
        }
    
        // Using a DependencyProperty as the backing store for CanFocusParent.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CanFocusParentProperty =
            DependencyProperty.RegisterAttached("CanFocusParent", typeof(bool), typeof(ListBoxHelper), new UIPropertyMetadata(false, OnCanFocusParentChanged));
    
    
    
        #endregion
    
        private static void OnCanFocusParentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var element = obj as UIElement;
            if(element == null) return;
    
            if((bool)args.NewValue)
                element.PreviewMouseDown += FocusOnParent;
            else
                element.PreviewMouseDown -= FocusOnParent;
        }
    
        private static void FocusOnParent(object sender, RoutedEventArgs e)
        {
            var listBoxItem = VisualUpwardSearch<ListBoxItem>(sender as DependencyObject) as ListBoxItem;
            if (listBoxItem != null) listBoxItem.IsSelected = true;
        }
    
        public static DependencyObject VisualUpwardSearch<T>(DependencyObject source)
        {
            while (source != null && source.GetType() != typeof(T))
                source = VisualTreeHelper.GetParent(source);
    
            return source;
        }
    }
    

    What this little class does is help your control to focus on the ListBox selected item when you activate a control inside it (ie. your ComboBox). It works when the Mouse is clicked inside the ListBox item.

    Now all you have to do is attach it to your ComboBox like so:

    <DataTemplate x:Key="myDataTemplate">
      <ComboBox
          TitleText="{Binding Title}"
          DescriptionText="{Binding DescriptionText}"
          CotrolHelper:ListBoxHelper.CanFocusParent="true"/>
    </DataTemplate>
    

    Where ControlHelper is:

    xmlns:ControlHelper="clr-namespace:WhereYouPutYour.ListBoxHelperClass"
    

    And finally, to Disable (but I recommend setting to Auto) the Scrollbar, you can use the ScrollViewer attached property in your ListBox like this:

    <ListBox
        x:Name="SettingListBox"
        Template="{StaticResource myDataTemplate}"
        ScrollViewer.VerticalScrollBarVisibility="Disabled" >
        <Item>
            <Setting Title="Foo" Description="Bar">
                <Option>Yes</Option><Option>No</Option>
            </Setting>
        </Item>
    </ListBox >
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.