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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:09:02+00:00 2026-06-02T01:09:02+00:00

The combobox binding below works if I specify the ancestor, but otherwise not. Why

  • 0

The combobox binding below works if I specify the ancestor, but otherwise not. Why doesn’t it work if I don’t specify the ancestor?

<wpftoolkit:DataGrid Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2"
                         Margin="5"
                         BorderBrush="#A6A6A6"
                         BorderThickness="1"
                         ItemsSource="{Binding DebitListing}"
                         AutoGenerateColumns="False"
                         SelectionMode="Single">
        <wpftoolkit:DataGrid.Columns>
            <wpftoolkit:DataGridComboBoxColumn
                Header="{Resx ResxName=MyBooks.Properties.Strings, Key=PartyListing_Party_Label}"
                SelectedItemBinding="{Binding Party, ValidatesOnDataErrors=True}"
                DisplayMemberPath="Name">

                <wpftoolkit:DataGridComboBoxColumn.ElementStyle>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="ItemsSource" Value="{Binding Path=DataContext.CreditedAccounts, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
                    </Style>
                </wpftoolkit:DataGridComboBoxColumn.ElementStyle>
                <wpftoolkit:DataGridComboBoxColumn.EditingElementStyle>
                    <Style TargetType="{x:Type ComboBox}">
                        <Setter Property="ItemsSource" Value="{Binding Path=DataContext.CreditedAccounts, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}" />
                    </Style>
                </wpftoolkit:DataGridComboBoxColumn.EditingElementStyle>

            </wpftoolkit:DataGridComboBoxColumn>

            <wpftoolkit:DataGridTextColumn
                Header="{Resx ResxName=MyBooks.Properties.Strings, Key=PartyListing_Amount_Label}"
                Binding="{Binding Amount, ValidatesOnDataErrors=True}"/>
        </wpftoolkit:DataGrid.Columns>
    </wpftoolkit:DataGrid>
  • 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-02T01:09:04+00:00Added an answer on June 2, 2026 at 1:09 am

    The reason you need to reference the ancestor from which to get your desired DataContext is because the wpftoolkit changes the datacontext on its rendered child elements. You’ll find that this is true of almost all ListView/DataGrid controls – the child element DataContext is changed to reference the collection item the current row or column is representing. If you want something in the Template or Style of those child elements to be based on a property off the control’s DataContext, you need to use RelativeSource Ancestor to get to it.

    I understand that this is confusing, since in basic XAML, child elements always automatically inherit the data context of their parent element, but the DataContext is just like any other DependencyProperty, and complex controls can set it differently as they see fit.

    You can simplify your syntax if you like by giving your parent control (or whatever element the DataContext is set on) a name, like x:Name='ControlRoot'. Then when you need to get back to your root datacontext, you need only go:

    Value="{Binding ElementName=ControlRoot, Path=DataContext.CreditedAccounts}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use WPFToolkit's DataGrid control (and C#/.Net 3.5) to display a ComboBox
With the below binding in XAML, the selected item is not displayed in a
Unless I add DisplayMemberPath on the combobox it does not work. I think it
I am trying to populate a datagrid with one column as a combobox but
The Binding on the ComboBox Categories is not updating when a Division is selected.
I have a ComboBox that has the SelectedItem bound to the ViewModel. <ComboBox SelectedItem={Binding
I have a WPF CombBox as follows: <ComboBox ItemsSource={Binding Source={StaticResource myList}} SelectedItem={Binding Path=mySelectedItem} />
I have a combobox that is binding to an ObservableCollection of strings in an
Currently I have a ComboBox defined as: <ComboBox Name=comboItems ItemsSource={Binding Path=EnumDataItems} DisplayMemberPath=Description ToolTip={Binding Path=ToolTip}
I am having a binding update problem with my ComboBox. My ComboBox's ItemSource is

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.