Xamarin窗体转换器在页面消失时被调用?

问题描述 投票:0回答:1
<Label Grid.Row="0" Grid.Column="1"
    Text="{Binding Date, Converter={StaticResource localTimeConverter}, StringFormat='{0:MMMM dd, yyyy}'}"
    LineBreakMode="NoWrap"
    FontSize="16"
    Style="{DynamicResource FieldLabel}"/>

我有上面的Xaml和下面的转换器。

public class UtcToLocalDateTimeConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((DateTime)value).ToLocalTime();
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}

然而,当页面开始时,转换器没有被调用,相反,当导航离开页面时,转换器被调用。我在convert方法中添加了一个中断点,这时该方法就被调用了。这真让人困惑!?

请谁能提供一些帮助?

xamarin.forms converters
1个回答
0
投票

Whoops ! 这是我的错。

我将转换器添加到ListView的SelectedItemTemplate中,而不是ListView的ItemTemplate中。这就是为什么转换器从未被调用的原因。现在都修好了。

© www.soinside.com 2019 - 2024. All rights reserved.