Xamarin表单中的绑定错误 [英] Binding errors in Xamarin Forms
本文介绍了Xamarin表单中的绑定错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在开发Xamarin Forms应用程序时,是否可以查看绑定错误? 应用程序输出"选项卡什么都没有显示,但是绑定不起作用.如何调试绑定?
Is there a way I can see the binding errors in while developing Xamarin Forms apps? The Application Output tab shows nothing but the binding doesn't work. How can I debug bindings?
推荐答案
我建议您添加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;
}
}
然后在您的页面上创建转换器实例:
Then create instance of converter on your page:
<ContentPage.Resources>
<ResourceDictionary>
<converters:EmptyConverter x:Key="EmptyConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
然后将转换器添加到标签:
Then add converter to label:
<Label Text="{Binding Text, Converter={StaticResource EmptyConverter}}"/>
在Convert
和ConvertBack
方法中放置断点,您将能够看到绑定值的所有变化.
Put breakpoints in Convert
and ConvertBack
methods and you'll be able to see all changes of binded values.
希望这会对您有所帮助.
Hope this will help you.
这篇关于Xamarin表单中的绑定错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文