首页 文章

Xamarin表单中的绑定错误

提问于
浏览
0

有没有办法在开发Xamarin Forms应用程序时看到绑定错误? “应用程序输出”选项卡只显示绑定不起作用 . 我该如何调试绑定?

2 回答

  • 4

    我想建议你添加 EmptyConverter

    public class EmptyConverter : IValueConverter
    {
        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;
        }
    }
    

    然后在您的页面上创建转换器实例:

    <ContentPage.Resources>
        <ResourceDictionary>
          <converters:EmptyConverter x:Key="EmptyConverter"/>
        </ResourceDictionary>
    </ContentPage.Resources>
    

    然后将转换器添加到标签:

    <Label Text="{Binding Text, Converter={StaticResource EmptyConverter}}"/>
    

    ConvertConvertBack 方法中放置断点,您将能够看到绑定值的所有更改 .

    希望这会帮助你 .

  • 0

    您可以尝试使用Compiled Bindings:https://docs.microsoft.com/it-it/xamarin/xamarin-forms/app-fundamentals/data-binding/compiled-bindings

    您将获得性能和精确的错误报告

相关问题