Does anyone get any information when a Binding is wrong (in Visual Studio)?

When a binding is bad in Xamarin Forms (Android or UWP) I don't get any information, it just raises an Exception at the highest level.
Am I supposed to get any debug information? In the current case I know where it is bad because it is the latest change I made but I'm not very comfortable with the feeling that a problem might arise in the future and I will have no idea at all where it is coming from.
I am using Visual Studio 2017.

Answers

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭
    edited October 8

    @AnthonyWaters.7746 - I switch to debugging on Android when I want to check bindings, as I then get messages such as the following in the Output window of Visual Studio 2017 (and 2015):

    Binding: 'Missing' property not found on 'ViewsUsingXamarinForms.FramedEntry', target property: 'ViewsUsingXamarinForms.Entry.Text'
    

    For debugging bindings, it can be useful to add a dummy value converter to bindings, as you can then apply breakpoints in Convert and ConvertBack to see what is happening in the case where properties are found:

        /// <summary>
        /// This converter class is used to help debug binding issues.
        /// </summary>
        public class MyAppDummyConverter : IValueConverter
        {
            public static MyAppDummyConverter Instance = new MyAppDummyConverter();
    
            private MyAppDummyConverter()
            {
                // no-op
            }
    
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return value;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return value;
            }
    
        } // public class MyAppDummyConverter : IValueConverter
    
  • AnthonyWaters.7746AnthonyWaters.7746 GBMember ✭✭

    @JohnHardman said:
    @AnthonyWaters.7746 - I switch to debugging on Android when I want to check bindings, as I then get messages such as the following in the Output window of Visual Studio 2017 (and 2015):

    Binding: 'Missing' property not found on 'ViewsUsingXamarinForms.FramedEntry', target property: 'ViewsUsingXamarinForms.Entry.Text'
    

    For debugging bindings, it can be useful to add a dummy value converter to bindings, as you can then apply breakpoints in Convert and ConvertBack to see what is happening in the case where properties are found:

        /// <summary>
        /// This converter class is used to help debug binding issues.
        /// </summary>
        public class MyAppDummyConverter : IValueConverter
        {
            public static MyAppDummyConverter Instance = new MyAppDummyConverter();
    
            private MyAppDummyConverter()
            {
                // no-op
            }
    
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return value;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                return value;
            }
    
        } // public class MyAppDummyConverter : IValueConverter
    

    I don't think I ever see a Debug message such as that. Certainly not in the latest case I was struggling with. I have fixed that particular problem but I wanted to improve the debugging for the future. In my particular case the Binding source was wrong, and I just get an exception, with no useful information. I also don't get a chance to use the converter as it can never get the value to convert.

  • AnthonyWaters.7746AnthonyWaters.7746 GBMember ✭✭

    I have just done a small test to confirm I don't get any debug messages about failed bindings.
    To repeat the test:
    1) Create a new Xamarin Forms project using PCL
    2) Add the following code in MainPage.xaml but don't add anything else

        <ListView ItemsSource="{Binding ListItems}">
        </ListView>
    

    3) Run the app in Android or UWP. Obviously the Binding fails because we haven't specified the DataContext or the ListItems property. However, I don't get any Debug messages about Binding. It just doesn't work.

    Do others experience this limitation? Please let me know.

  • LewisKLewisK USUniversity ✭✭

    Can't you use the following to get XAML warnings when its not mapped in a binding?

       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        xmlns:rootViewModel="clr-namespace:MyApp.ViewModels;assembly=MyApp"
        d:DataContext="{d:DesignInstance rootViewModel:LoginViewModel}"
    
  • ZoliZoli NLMember ✭✭

    I also have "Binding: 'Missing' property not found on ......" message in VS2017->Output pane.

  • Xami3Xami3 PKMember ✭✭✭
    edited October 10

    i dont think xf supports compile time binding like UWP has(the Bind instead of binding)

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭

    @Zoli - Do you get those binding messages when building for targets other than Android? TBH - I cannot remember if I get them for iOS, but I definitely do not for UWP even though I do for Android. I wonder if there's some configuration setting somewhere that enables/disables those messages?

  • ZoliZoli NLMember ✭✭

    @JohnHardman - No, I only tried for Android (and Debug version of course). But normal Desktop WPF/XAML apps also log such messages (as far as I remember)

  • AnthonyWaters.7746AnthonyWaters.7746 GBMember ✭✭

    Can someone please confirm that you get a debug message about missing Binding with my test described above.
    Assuming yes, does anyone have any ideas why I don't get anything in either Android or UWP?

  • AnthonyWaters.7746AnthonyWaters.7746 GBMember ✭✭

    By the way, I am using Visual Studio Community Edition. I wonder if that could be the problem? I think I remember reading something about Android logging not being complete in that version.

Sign In or Register to comment.