【问题标题】:UI won't load until click用户界面在点击之前不会加载
【发布时间】:2019-07-06 20:12:18
【问题描述】:

我最近首次在 iOS 上启动了我的 Xamarin 应用程序。该应用程序在 Android 上完美运行。但是,在 iOS 上,用户界面在我触摸屏幕之前不会完全加载。这与动态创建的绑定和 ui 元素有关。例如这个按钮:

<local:MainMenuButton Command="{Binding NavigateCommand}" CommandParameter="{Type local:page2}" CornerRadiusExtended="{Binding LeftCornersRounded}" Grid.Row="0" Grid.Column="0" HeightRequest="{Binding Width, Source={x:Reference ModelButton}}"/>

不会将其高度更改为 ModelButton 的高度。此外,ImageButtons 完全不可见(图像未加载)。单击屏幕后,一切都开始工作。有人知道发生了什么吗?

[编辑]:这甚至适用于我在代码中未引用的控件。例如:

<ImageButton Style="{StaticResource UiButton}" Grid.Row="0" Grid.Column="0" Command="{Binding SetLanguageCommand}" CommandParameter="EN" Source="{helpers:ImageResourceExtension imagesource.png}"/>

// Extension code

[ContentProperty("Source")]
public class ImageResourceExtension : IMarkupExtension
{
    public string Source { get; set; }

    public object ProvideValue(IServiceProvider serviceProvider)
    {
        if (Source == null)
            return null;

        var imageSource = ImageSource.FromResource(Source);

        return imageSource;
    }
}

ImageButton 在点击之前不会加载它的源代码。如果我删除绑定并直接输入源代码,一切正常。 我使用调试器检查扩展代码是在页面启动时执行还是在单击后执行,结果发现它在启动时运行。但是由于某种原因,点击后图像仍然显示。

【问题讨论】:

  • 您好,尝试在OnAppearing()方法中更新模型数据。
  • @JuniorJiang-MSFT 不幸的是,它不起作用。
  • 好的,您能否在 ContentPage 中启动应用程序时显示一些有关更新模型数据的代码。
  • @JuniorJiang-MSFT 我编辑了我的帖子。该问题甚至适用于我在代码中未引用的控件,因此它可能与更新模型数据无关。
  • 知道了,尝试将绑定模式设置为 TwoWay 。 HeightRequest="{Binding Width, Source={x:Reference ModelButton},Mode=TwoWay}"

标签: xamarin xamarin.forms xamarin.ios


【解决方案1】:

我已收到 Microsoft 支持部门的回复。他们找到了问题的根源。这是一个名为 Forms9Patch 的 NuGet 包,它导致了问题 (https://baskren.github.io/Forms9Patch/)。目前尚不清楚它如何影响渲染,但从项目中删除包解决了这个问题。我会联系包所有者。

【讨论】:

    猜你喜欢
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    相关资源
    最近更新 更多