有没有办法可以在开发 Xamarin Forms 应用程序时查看绑定错误?“应用程序输出”选项卡不显示任何内容,但绑定不起作用。如何调试绑定?
我想建议您添加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;
}
}
Run Code Online (Sandbox Code Playgroud)
然后在您的页面上创建转换器的实例:
<ContentPage.Resources>
<ResourceDictionary>
<converters:EmptyConverter x:Key="EmptyConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
Run Code Online (Sandbox Code Playgroud)
然后将转换器添加到标签中:
<Label Text="{Binding Text, Converter={StaticResource EmptyConverter}}"/>
Run Code Online (Sandbox Code Playgroud)
Convert在和方法中放置断点ConvertBack,您将能够看到绑定值的所有更改。
希望对你有帮助。
| 归档时间: |
|
| 查看次数: |
1493 次 |
| 最近记录: |