动态更新 Xamarin.Forms ContentPage 内容不响应 iOS 平台的用户操作
Dynamically updated Xamarin.Forms ContentPage Content doesn't respond to user actions for iOS platform
在我的 Xamarin.Forms 项目中,该项目同时针对 iOS 和 Android 平台,我正在尝试通过以下方式动态更改 ContentPage
的 Content
,
var currentPage = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
var oldContent = ((ContentPage)currentPage).Content;
var testLabel = new Label { Text = "Hello" };
var newContent = new Grid { Children = {oldContent, testLabel } };
((ContentPage)currentPage).Content = newContent;
这将在 oldContent
之上成功显示 testLabel
。
在 Android 平台中,我仍然可以在 oldContent
视图中与子元素(按钮、ListView...等)进行交互。但是在 iOS 中,oldContent
视图子元素在这个阶段是不可交互的。
我还确保 testLabel
不会阻塞 oldContent
。这就是我确保它不会阻塞的方法,
var currentPage = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
var oldContent = ((ContentPage)currentPage).Content;
var newContent = new Grid { Children = { oldContent } };
((ContentPage)currentPage).Content = newContent;
同样对于此设置,它仅适用于我可以与 oldContent
子元素交互的 Android 平台。但是对于 iOS 平台,我无法与 oldContent
子元素进行交互。
此外,当我将 oldContent
设置回 ContentPage
的 Content
时,我可以与 oldContent
元素交互。在相同的应用程序流程中。
((ContentPage)currentPage).Content = oldContent;
这允许我与 Android 和 iOS[=61= 的 oldContent
子元素交互] 平台。
有没有人知道如何在动态更改 Content[ 后,让 oldContent
仍然与 iOS 平台交互? =61=] ContentPage.
我刚刚做到了,
我尝试将 newContent
创建为空 Element
。然后将 ContentPage
的 Content
替换为 newContent
。然后将相关的子元素添加到 newContent
中,如下所示。
var newContent = new Grid ();
((ContentPage)currentPage).Content = newContent;
newContent.Children.Add(oldContent);
newContent.Children.Add(testLabel);
还有宾果!!!有效
在我的 Xamarin.Forms 项目中,该项目同时针对 iOS 和 Android 平台,我正在尝试通过以下方式动态更改 ContentPage
的 Content
,
var currentPage = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
var oldContent = ((ContentPage)currentPage).Content;
var testLabel = new Label { Text = "Hello" };
var newContent = new Grid { Children = {oldContent, testLabel } };
((ContentPage)currentPage).Content = newContent;
这将在 oldContent
之上成功显示 testLabel
。
在 Android 平台中,我仍然可以在 oldContent
视图中与子元素(按钮、ListView...等)进行交互。但是在 iOS 中,oldContent
视图子元素在这个阶段是不可交互的。
我还确保 testLabel
不会阻塞 oldContent
。这就是我确保它不会阻塞的方法,
var currentPage = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
var oldContent = ((ContentPage)currentPage).Content;
var newContent = new Grid { Children = { oldContent } };
((ContentPage)currentPage).Content = newContent;
同样对于此设置,它仅适用于我可以与 oldContent
子元素交互的 Android 平台。但是对于 iOS 平台,我无法与 oldContent
子元素进行交互。
此外,当我将 oldContent
设置回 ContentPage
的 Content
时,我可以与 oldContent
元素交互。在相同的应用程序流程中。
((ContentPage)currentPage).Content = oldContent;
这允许我与 Android 和 iOS[=61= 的 oldContent
子元素交互] 平台。
有没有人知道如何在动态更改 Content[ 后,让 oldContent
仍然与 iOS 平台交互? =61=] ContentPage.
我刚刚做到了,
我尝试将 newContent
创建为空 Element
。然后将 ContentPage
的 Content
替换为 newContent
。然后将相关的子元素添加到 newContent
中,如下所示。
var newContent = new Grid ();
((ContentPage)currentPage).Content = newContent;
newContent.Children.Add(oldContent);
newContent.Children.Add(testLabel);
还有宾果!!!有效