动态更新的Xamarin.Forms ContentPage内容不';无法响应iOS平台的用户操作

动态更新的Xamarin.Forms ContentPage内容不';无法响应iOS平台的用户操作,xamarin.forms,xamarin.ios,Xamarin.forms,Xamarin.ios,在我的Xamarin.Forms项目中,我试图通过以下方式动态更改ContentPage的Content,该项目同时针对iOS和Android平台 var currentPage = Application.Current.MainPage.Navigation.NavigationStack.LastOrDefault(); var oldContent = ((ContentPage)currentPage).Content; var testLabel = new Label { Text

在我的Xamarin.Forms项目中,我试图通过以下方式动态更改
ContentPage
Content
,该项目同时针对iOSAndroid平台

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

在安卓平台中,我仍然可以与
oldContent
视图中的子元素(按钮、列表视图等)进行交互。但是在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;
对于这种设置,我只能在Android平台上与
oldContent
子元素进行交互。但是对于iOS平台,我无法与
oldContent
子元素交互

另外,当我将
oldContent
设置回
ContentPage
Content
时,我可以与
oldContent
元素交互。在相同的应用程序流中

((ContentPage)currentPage.Content=oldContent

这使我能够与
oldContent
子元素进行交互,用于AndroidiOS平台


有人知道我如何在动态更改ContentPage的内容后,使
旧内容在iOS平台上保持交互吗

我尝试将
newContent
创建为空的
元素
。然后将
ContentPage
Content
替换为
newContent
。然后将相关子元素添加到
newContent
中,如下所示

var newContent = new Grid ();
((ContentPage)currentPage).Content = newContent;
newContent.Children.Add(oldContent);
newContent.Children.Add(testLabel);

还有宾果!!!它成功了我只是设法做到了

我尝试将
newContent
创建为空的
元素
。然后将
ContentPage
Content
替换为
newContent
。然后将相关子元素添加到
newContent
中,如下所示

var newContent = new Grid ();
((ContentPage)currentPage).Content = newContent;
newContent.Children.Add(oldContent);
newContent.Children.Add(testLabel);

还有宾果!!!谢谢你的分享。不要忘记接受答案。谢谢分享。别忘了接受答案。