MAUI Community Toolkit IconTintColorBehavior在iOS平台运行时着色失效问题求助
MAUI Community Toolkit IconTintColorBehavior在iOS平台运行时着色失效问题求助
各位大佬好,我遇到一个MAUI跨平台开发的问题,想请教下大家:
我现在做的功能是在CollectionView里,基于应用主题(AppTheming),通过MAUI Community Toolkit的IconTintColorBehavior在运行时给图标着色。具体流程是:页面会遍历每个任务,模拟调用服务器数据库(用await Task.Delay()来模拟网络请求延迟),请求完成后把鸡蛋计时器图标替换成对勾图标,图标颜色要跟随主题变化。
目前大部分功能都正常,但仅在iOS平台上,IconTintColorBehavior的着色效果不生效,图标会保留原始颜色;Android平台完全正常。而且我发现只要去掉代码里的await Task.Delay(),iOS上的着色就能正常工作,其他有类似延迟逻辑的视图也出现了同样的问题。
数据是放在ObservableCollection里绑定给CollectionView的,以下是相关代码:
1. 执行任务的RelayCommand方法
[RelayCommand] async Task StartProcess() { if (await Shell.Current.DisplayAlert("End of Month Report", "Are you sure you want to run the End of Month Report?\n\nThis process will log off all active users.", "Yes", "No")) { EnableControl = false; for (int i = 0; i < Processes.Count; i++) { Processes[i] = Process(Processes[i], ProcessResult.Processing, true); await Task.Delay(1500); Processes[i] = Process(Processes[i], ProcessResult.Completed, false); } await Shell.Current.DisplayAlert("Month End Report", "Month end report completed successfully. ", "Ok"); } }
2. 更新任务状态的方法
MonthEndProcess Process(MonthEndProcess mep, ProcessResult result, bool IsBusy) { MonthEndProcess process = new MonthEndProcess { completed = result == ProcessResult.Processing ? result.ToString() : result.ToString() + DateTime.Now.ToString(" dd/MM/yyyy hh:mm:ss tt"), description = mep.description, name = mep.name, IsBusy = IsBusy, status = result.ToString() }; return process; }
3. CollectionView模板里的Image及Behavior代码
<Image Source="{Binding status, Converter={StaticResource MonthEndIconConverter}}" Grid.Column="0" Grid.RowSpan="2" HeightRequest="40" WidthRequest="40" VerticalOptions="Center" HorizontalOptions="Center" Margin="8" IsVisible="{Binding IsBusy, Converter={StaticResource InvertedBoolConverter}}"> <Image.Behaviors> <mct:IconTintColorBehavior TintColor="{AppThemeBinding Dark={StaticResource ListIconColourDark},Light={StaticResource ListIconColour}}" /> </Image.Behaviors> </Image>
有没有大佬遇到过类似的问题?或者能给我一些排查方向?非常感谢!
备注:内容来源于stack exchange,提问作者steve lang
相关产品推荐
相关产品推荐

