none
RelativeSource is not in FindAncestor mode RRS feed

  • Question

  • I'm not sure why I'm getting this error in WPF. All of my other DependencyProperties are bound the exact same way and not giving me the error.

    For example...

    <TextBlock Text="{Binding Path=CurrentError, RelativeSource={RelativeSource AncestorType=UserControl}}" Foreground="{Binding Path=ErrorForeground, RelativeSource={RelativeSource AncestorType=UserControl}}" />

    Binding to Text works as expected and with no errors, but Foreground is saying "RelativeSource is not in FindAncestor mode."

    What could cause this?

    Here are the DependencyProperties...

    public double CurrentError
            {
                get { return (double)GetValue(CurrentErrorProperty); }
                set { SetValue(CurrentErrorProperty, value); }
            }
            public static readonly DependencyProperty CurrentErrorProperty = DependencyProperty.Register("CurrentError", typeof(double), typeof(MyCustomUserControl), new PropertyMetadata(0.0));
    
    
    public SolidColorBrush ErrorForeground
            {
                get { return (SolidColorBrush)GetValue(ErrorForegroundProperty); }
                set { SetValue(ErrorForegroundProperty, value); }
            }
            public static readonly DependencyProperty ErrorForegroundProperty = DependencyProperty.Register("ErrorForeground", typeof(SolidColorBrush), typeof(MyCustomUserControl), new PropertyMetadata(Brushes.Black));

    Wednesday, October 9, 2019 9:17 PM

Answers

  • Hi,

    I tried your code ,showed the same warning as you, but the program runs without exception.

    I rebuild my program and the warning disappears.

    Best Regards,

    Alex




    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.

    • Marked as answer by T Gregory Friday, October 11, 2019 5:40 PM
    Thursday, October 10, 2019 3:20 AM
    Moderator
  • Strange. I built and built and the error stayed. I closed and reopened Visual Studio and the error is gone.

    Must've been some bug in WPF. Thanks for testing!

    • Marked as answer by T Gregory Friday, October 11, 2019 5:40 PM
    Thursday, October 10, 2019 10:06 AM

All replies

  • Hi,

    I tried your code ,showed the same warning as you, but the program runs without exception.

    I rebuild my program and the warning disappears.

    Best Regards,

    Alex




    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.

    • Marked as answer by T Gregory Friday, October 11, 2019 5:40 PM
    Thursday, October 10, 2019 3:20 AM
    Moderator
  • Strange. I built and built and the error stayed. I closed and reopened Visual Studio and the error is gone.

    Must've been some bug in WPF. Thanks for testing!

    • Marked as answer by T Gregory Friday, October 11, 2019 5:40 PM
    Thursday, October 10, 2019 10:06 AM
  • Hi,

    Is your problem solved? If so, please mark your reply as answer.  

    Bets Regards,

    Alex


    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, October 11, 2019 1:33 AM
    Moderator