Tag: xamarin.forms

如何使Label显示带有不同颜色字母的FormattedString?

我使用FormattedString在Xamarin.Forms上的Label上显示自定义文本。 我想要实现的是改变一个或多个元素的颜色,例如: $$ $$。 但即使我改变颜色,Label也会显示所有具有相同颜色的美元符号:$$$$ 这是视图上的标签: 这是绑定到ViewModel上的标签文本的属性的代码 public FormattedString AveragePrice { get { return new FormattedString { Spans = { new Span { Text = “$”, ForegroundColor=Color.Black }, new Span { Text = “$”, ForegroundColor=Color.Black }, new Span { Text = “$”, ForegroundColor=Color.Gray }, new Span { Text = “$”, ForegroundColor=Color.Gray } } }; } […]

Xamarin表单从文本文件读取结果是空的

我的项目文件资源管理器中有data.txt文件。 我想从这个文本文件中读取数据,但每次尝试时,结果都为null,程序崩溃。 我写的代码是: public MapPage() { var assembly = typeof(MapPage).GetTypeInfo().Assembly; Stream stream = assembly.GetManifestResourceStream(“Mapper.data.txt”); string text = “”; using (var reader = new System.IO.StreamReader(stream)) { text = reader.ReadToEnd(); } } 使用此代码块,流始终为空。 这是项目文件资源管理器: 我从其属性中选择文本文件作为嵌入式资源。

如何在Xamarin WebView中访问cookie?

在我们的Xamarin应用程序中,我们需要允许用户使用自己的SSO解决方案登录。 这在我们的iOS应用程序中的工作方式是我们打开一个带有Web视图的控制器并将其指向我们的站点,并继续观察cookie,直到他们回到我们的站点上,并使用指示他们已登录的cookie但是在Xamarin中,我看不出如何访问WebView的cookie。 我们的Xamarin应用程序运行在Windows 8.1和WinPhone 8.1上,但它将在某些时候扩展到Android,因此我需要一个跨平台的解决方案。 那么,我如何在Xamarin WebView中访问cookie?

Xamarin.Forms – 标签FontSize OnPlatform – XAML错误

我有这个代码: …并得到此错误: No property, bindable property, or event found for FontSize 我做错了什么? 谢谢。

如何使用Xamarin和Autofac将构造函数依赖项注入ViewModel?

我有一个ViewModel,我想在其中注入另一个类。 我正在使用Visual Studio和最新版本的Xamarin。 我正在使用Autofac来注册解析依赖项。 但我是新手,我遇到了一个我无法找到解决方案的问题,即使它可能很简单。 这是我想要注入另一个类的类: public IMessagingCenterWrapper MessagingCenterWrapper; public LoginViewModel(IMessagingCenterWrapper messagingCenterWrapper){ MessagingCenterWrapper = messagingCenterWrapper; } 然后在应用程序的入口点我有一个函数初始化容器,它注册并解析依赖项 static IContainer container{ get; set; } public App () { InitializeComponent(); InitializeIOCContainer(); } void InitializeIOCContainer() { var builder = new ContainerBuilder(); builder.RegisterType(); builder.RegisterType().As(); container = builder.Build(); var wrapper = container.Resolve(); var viewModel = container.Resolve(); } 但是在登录视图中的行中构建时出错: BindingContext = […]

Xamarin表单Visual Studio 2015 HttpClient请求不在iOS上运行

我对Xamarin Forms / Visual Studio很新,但这是我目前的情况。 我在Visual Studio中有一个带有Android,iOS和Windows Phone子项目的Xamarin Forms项目。 我有以下function登录: public async Task<Tuple> Login(LoginCredentials credentials) { var loginUrl = apiUrl + “/login”; var json = JsonConvert.SerializeObject(credentials); var content = new StringContent(json, Encoding.UTF8, “application/json”); try { Debug.WriteLine(“start of try block”); HttpResponseMessage response = await client.PostAsync(loginUrl, content); Debug.WriteLine(“this will not print on iOS”); string bodyStr = await […]

Xamarin.form页面导航在mvvm中

我正在开发xamarin.form跨平台应用程序,我希望在按钮点击时从一个页面导航到另一个页面。 因为我不能做Navigation.PushAsync(new Page2()); 在ViewModel中,因为它只能在Code-Behid文件中使用。 请建议任何方式这样做? 这是我的观点: 这是我的ViewModel: public class LocalAccountViewModel : INotifyPropertyChanged { public LocalAccountViewModel() { this.ContinueBtnClicked = new Command(GotoPage2); } public void GotoPage2() { ///// } public ICommand ContinueBtnClicked { protected set; get; } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanges([CallerMemberName] string PropertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(PropertyName)); } }

Xamarin.UITesting NU1201错误:Android 8.1与.NETFramework 4.6.1不兼容

在过去的几天里我一直有一个小问题,我将在Visual Studio 2017上创建一个新的Xamarin Forms项目并添加一个Xamarin.UITest跨平台测试项目进行unit testing我在参考时收到一系列NU1201错误UITest项目中的.Android应用程序。 这是我得到的确切错误: Error NU1201 Project App1.Android is not compatible with net461 (.NETFramework,Version=v4.6.1) / win-x64. Project App1.Android supports: monoandroid81 (MonoAndroid,Version=v8.1) 我玩过Android版本的数字,看看UITesting软件包是否支持最新的android,但不管是什么版本的android i目标,问题依然存在。 这是该项目的屏幕截图。 所有代码都与默认项目保持不变,并在模拟器中运行良好,但只有在Android应用程序被引用到UITest项目时才会产生这些错误。

Xamarin表单 – 让webview回归

大家早, 我正在开发Xamarin.Forms中的一个小型跨平台webview项目。 我有webview工作,但我想添加一个工具栏,其中有一个后退和前进按钮。 我尝试了许多不同的方法,但似乎没有什么工作特别好。 我试着按照这个人发布导航工具栏来实现这个function 我将在下面附上我的代码,如果有人可以帮我解决这个或者一个很棒的解决方案! 如果此问题已经被其他用户先前回答,那么我道歉。 App.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using Xamarin.Forms; namespace DisplayWebPage { public class App : Application { public App() { // The root page of your application MainPage = new WebPage(); } protected override void OnStart() { // Handle when your app starts } protected […]

“您是否在visual studio 2013中缺少using指令或汇编参考”

今天是个好日子。 我在Xamarin.Forms中开发跨平台应用程序时遇到此错误“您是否缺少using指令或程序集引用”。 在安装Nuget软件包(Xamarin中的Circle Image View)之前,我的项目工作正常,但是当我卸载它时(不更改单行代码),所述错误开始出现。 我尝试构建,重建它但仍然不起作用。 我能做些什么来解决这个问题? 任何帮助将不胜感激。 非常感谢。 这些是错误: 错误1: 找不到类型或命名空间名称’Xamarin’(您是否缺少using指令或程序集引用?) 错误2: 找不到类型或命名空间名称“Application”(您是否缺少using指令或程序集引用?) 错误3: 找不到类型或命名空间名称’Xamarin’(您是否缺少using指令或程序集引用?) 错误4: 找不到类型或命名空间名称’ContentPage’(您是否缺少using指令或程序集引用?)