WPF, XAML, Combobox: Cannot find source for binding with reference RRS feed

  • Question

  • I have some comboboxes that use the same possible input values. Hence I tried to create a style and then set the style on my combo boxes. However, I am getting the error

    System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')

    My style is defined as

            <Style TargetType="{x:Type ComboBox}" x:Key="MyCombobox" xmlns:c="clr-namespace:System.Collections;assembly=mscorlib">
                <Setter Property="ItemsSource">

    Then my comboboxes are defined as

       <ComboBox x:Name="comboBox1" Text="{Binding Path=Input1}" Style="{StaticResource MyCombobox}" />
       <ComboBox x:Name="comboBox2" Text="{Binding Path=Input2}" Style="{StaticResource MyCombobox}" />

    Input1 and Input2 are text properties in my VM. So why am I getting this error?

    Thursday, June 11, 2020 11:42 PM

All replies

  • Hi hfaun,

    Thank you for posting here.

    According to your description, your issue is more related to WPF. Therefore, it will be more appropriate to ask your question in WPF forum.

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.
    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 12, 2020 2:36 AM
  • Ok, I posted the same question at the link below. So if anybody has the same problem please follow that link. For some reason I had to create a new account so my "credentials" start back at 0... :(


    Friday, June 12, 2020 6:26 AM