配合James Montemagno的Component [Settings Plugin],实现Xamarin.Forms的设置。

更新系统配置且不需要进行重启app。

方式一xml

Xamarin.forms 并不具备App.config 的概念。但是我们可以添加等价的xml和资源解析器。

例如:添加webservices请求地址。

Xamarin.forms 右键 添加新项-》xml文件(config.xml)

属性-》生成操作-》嵌入的资源

添加XML文件作为嵌入资源可以很容易在运行时的应用程序设置阅读

<?xml version="1.0" encoding="utf-8" ?>

<config>

<google-api-key>YourGoogleApiKeyHere</google-api-key>

</config>

读取方式:

string GetGoogleApiKey() {

var type = this.GetType();

var resource = type.Namespace + "." +
Device.OnPlatform("iOS", "Droid", "WinPhone") + ".config.xml";

using (var stream = type.Assembly.GetManifestResourceStream(resource))

using (var reader = new StreamReader(stream)) {

var doc = XDocument.Parse(reader.ReadToEnd());

return doc.Element("config").Element("google-api-key").Value;

}

}

方式二 Settings Plugin

在运行时采用.NET API加载资源配置文件

右键添加NUGET引用:

自动生成Helpers

使用

this.url = Helpers.Settings.Pdaservices;

 

Helpers.Settings.Pdaservices = "111111111111111";

 

var sst = Helpers.Settings.Pdaservices;

直接采用属性方式是推荐方式,不需要担心xml明文问题,能够自动更新保存

Xamarin.Forms App Settings的更多相关文章

  1. Add AI feature to Xamarin.Forms app

    Now, AI is one of important technologies.Almost all platforms have API sets of AI. Following list is ...

  2. Xamarin.Forms 开发资源集合(复制)

    复制:https://www.cnblogs.com/mschen/p/10199997.html 收集整理了下 Xamarin.Forms 的学习参考资料,分享给大家,稍后会不断补充: UI样式 S ...

  3. Xamarin.Forms 开发资源集合

    收集整理了下 Xamarin.Forms 的学习参考资料,分享给大家,稍后会不断补充: UI样式 Snppts: Xamarin Forms UI Snippets. Prebuilt Templat ...

  4. 整理 Xamarin.Forms - Plugins

    Open Source Components for Xamarin Xamarin官方整理的一些开源组件,有需要可以先到这里找 GitHub: xamarin/XamarinComponents: ...

  5. Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面

    Xamarin.iOS - 利用Settings插件与EAIntroView制作App的欢迎界面 关于欢迎界面 很多App第一次启动都会有一个欢迎界面,欢迎界面往往决定这用户对App的第一映像,所以欢 ...

  6. 菜鸟的Xamarin.Forms前行之路——从新建项目到APP上架各种报错问题解决方法合集(不定时更新)

    出自:博客园-半路独行 原文地址:http://www.cnblogs.com/banluduxing/p/7425791.html 本文出自于http://www.cnblogs.com/banlu ...

  7. 【Xamarin.Forms 1】App的创建与运行

    引言 本篇文章将从介绍Xamarin.Forms创建开始. 开发环境 Visual Studio 2019 16.6.2 Xamarin.Forms 4.6.0.726 Android 5.0 (AP ...

  8. 【Xamarin.Forms 2】App基础知识与App启动

    系列目录 1.[Xamarin.Forms 1]App的创建与运行 引言 本篇文章将介绍Xamarin.Forms中 App 基础知识和 App的启动. 开发环境 Visual Studio 2019 ...

  9. Xamarin.Forms开发APP

    Xamarin.Forms+Prism(1)—— 开发准备 准备: 1.VS2017(推荐)或VS2015: 2.JDK 1.8以上: 3.Xamarin.Forms 最新版: 4.Prism 扩展, ...

随机推荐

  1. 修改CKFinder上传路径

    一.CKFinder的若干问题 1.单独使用 ckfinder从原fckeditor分离出来以后可以单独使用,通常我习惯于在工具栏中添加ckfinder.dll,这样以后要使用ckfinder直接从工 ...

  2. struct 结构

    //原始套接字学习笔记之代码结构 /* *host端程序结构 */ #include <> #define .. //主函数 int main() { //建立发送线程 pthread_t ...

  3. Django 安装MySQLdb模块

    首先装 mysql的时候 我用的是 apt-get  install mysql-client-core-5.1  (当时以为core的牛逼)  其实直接安mysql-client-5.1就行了 问题 ...

  4. [置顶] Hash查找,散列查找

    //Hash.h #ifndef HASH_H #define HASH_H #define HASH_ARR_SIZE 100 #define FILL -1 #include <stdlib ...

  5. CentOS 6.3下rsync服务器的安装与配置[转]

    CentOS 6.3下rsync服务器的安装与配置   一.rsync 简介 Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件,也 ...

  6. [Unit Testing] Angular Test component with required

    export default (ngModule) => { describe('Table Item component', () => { let $compile, directiv ...

  7. Android TableLayout 常用的属性介绍及演示

    TableLayout经常用的属性是: 1.android:collapseColumns:以第0行为序,隐藏指定的列:把android:collapseColumns=0,2 意思是把第0和第2列隐 ...

  8. Injecting and Binding Objects to Spring MVC Controllers--转

    I have written two previous posts on how to inject custom, non Spring specific objects into the requ ...

  9. Eclipse中Java文件图标由实心J变成空心J的问题

    在eclipse中空心J的java文件,表示不被包含在项目中进行编译,而是当做资源存在项目中.例如 当是单个文件为空心J的时候 1.右击该文件 -- >BuildPath -->Inclu ...

  10. Mounting File Systems

    1.Mounting File Systems Just creating a partition and putting a file system on it is not enough to s ...