gpt4 book ai didi

ios - 使用 Xamarin.Forms 更新 ListView 文本绑定(bind)会导致 iOS 上闪烁

转载 作者:行者123 更新时间:2023-11-29 05:20:40 33 4
gpt4 key购买 nike

我正在开发一个 Xamarin.Forms 聊天应用程序,它逐字符发送/接收文本,这意味着 ListView 行上的文本绑定(bind)每 1-2 秒或半秒更新一次(取决于打字速度), Android 上的 ListView 项目更新顺利,但在 iOS 上,它会随着每个输入的字符而闪烁/脉动,就像频闪灯一样。

编辑复制步骤:将 Listview 的 ItemSource 绑定(bind)到 ObservableCollection,该集合会针对在 Entry 中键入的每个新字符进行更新。使用带有标签的 DataTemplate,该标签显示在“条目”字段中键入的文本。

在Page.xaml中

<ListView HasUnevenRows="True" ItemsSource="{Binding ObservableCollection}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid>
<Label Text="{Binding Text}"/>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Entry Text="{Binding UserText}"/>

在 PageViewModel.cs 中

    /// <summary>
/// Gets or sets the text entered by the user
/// </summary>
public string UserText
{
get
{
return this.userText;
}

set
{
this.SetProperty(ref this.userText, value);

// Display text by updating listview
Device.BeginInvokeOnMainThread(() =>
{
this.ObservableCollection.Add(userText);
});
}
}

最佳答案

我在 iOS 上创建了一个 ListViewRenderer 并设置 AnimationsEnabled = false。轻弹现在消失了!

关于ios - 使用 Xamarin.Forms 更新 ListView 文本绑定(bind)会导致 iOS 上闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58708928/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com