首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LoadFromXAML不适用自定义命名空间。

LoadFromXAML不适用自定义命名空间。
EN

Stack Overflow用户
提问于 2022-02-07 11:13:24
回答 1查看 68关注 0票数 0

我正在开发一个应用程序,它需要从App服务器下载和显示XAML代码。到目前为止,我的代码工作正常,但现在我需要显示一个WebView,它需要访问GPS-数据(这些数据可以与android上的chrome浏览器一起使用)。我测试了实现和所有的东西。当在应用程序代码中编译XAML-代码时,一切都像一个字符一样工作。即使是XAML-Hot也能工作,但只要我尝试用以下代码加载内容页:

代码语言:javascript
复制
public static class GUIFramework
    {
        public static readonly string PRE_FRAMEWORK_XAML = "<ContentPage xmlns=\"http://xamarin.com/schemas/2014/forms\" xmlns:x=\"http://schemas.microsoft.com/winfx/2009/xaml\" xmlns:local=\"clr-namespace:Buerger_App.Renderer;assembly=Buerger_App\" x:Class=\"Buerger_App.Views.Framework\"><ContentPage.Content>";
        public static readonly string POST_FRAMEWORK_XAML = "</ContentPage.Content></ContentPage>";

        /// <summary>
        /// This Dictionary is used for caching all of the generated CententPages in the memory.
        /// This is needed due to the Page-XAML-Code needs to be compiled JIT and this can cause noticable delay.
        /// The Caching automatically jumps in after a page was loaded once.
        /// </summary>
        private static Dictionary<string, ContentPage> CachedContentPages = new Dictionary<string, ContentPage>();

        /// <summary>
        /// Loads the given XAML string as a new ContentPage and binds the Framework Binding-Context
        /// </summary>
        /// <param name="XAML_Content">A string representing the XAML formatted code</param>
        /// <returns>The newly created ContentPage</returns>
        public static ContentPage LoadFramework(string XAML_Content, string Title = "")
        {
            string pre_XAML = PRE_FRAMEWORK_XAML;
            if (Title != "")
            {
                pre_XAML = pre_XAML.Replace("<ContentPage ", "<ContentPage Title=\"" + Title + "\" ");
            }
            string FinalXAML = pre_XAML + XAML_Content + POST_FRAMEWORK_XAML;
            ContentPage ContentPage = null;

            // Use caching and read the XAML live from the phone and/or cache
            string hash = SHA256Hash.GetHash(FinalXAML);
            if (CachedContentPages.ContainsKey(hash))
                ContentPage = CachedContentPages[hash];
            else
            {
                ContentPage = new ContentPage().LoadFromXaml(FinalXAML);
                CachedContentPages.Add(hash, ContentPage);
            }

            ContentPage.BindingContext = new FrameworkViewModel();
            return ContentPage;
        }
        // More code ...
    }

我试着按照XAML代码加载(使用LoadFramework-function构建完整的XAML代码):

代码语言:javascript
复制
<StackLayout>
    <Image Source="logo_wide.jpg" Margin="0,0,0,25"/>
    <local:GeoWebView x:Name="WebView" Margin="10,0,10,0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Source="https://google.de" />
</StackLayout>

LoadFromXAML-扩展运行时没有任何错误(没有引发的异常)。它只跳过创建自定义GeoWebView (我可以在调试器中新创建的ContentPage的子程序中验证这一点)( ContentPage只有一个子级,这是在自定义WebView之前创建的图像)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-07 13:21:09

好吧,所以我四处摆弄了一下,找到了解决方案。我所遇到的问题也被描述为here。前面提到的将程序集键添加到XAML-代码中的名称空间的答案通常是正确的,但我在最初的问题中做错了(我添加了程序集-键,但使用了incrorrect程序集名称)。

测试中的问题是,我输入了Buerger_App作为程序集,这是我的默认名称空间,而不是程序集名称。我的组装名是Buerger App.

在修正了XAML代码之后,它开始像预期的那样工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71017609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档