Tag: xamarin

使用Xamarin Forms在Visual Studio中创建Hello World失败

我正在引用此解决方案/问题xamarin工作室中缺少类型或命名空间名称’Xamarin’ 但是,仍然无法从新的通用应用程序项目向导构建应用程序。 Severity Code Description Project File Line Suppression State Error CS0117 ‘Resource.Attribute’ does not contain a definition for ‘actionBarSize’ Project.Droid C:\dev\Project.Droid\Resources\Resource.Designer.cs 29 Active 从新到Xamarin人群的任何想法?

Xamarin.Forms.Color到hex值

我有一个Xamarin.Forms.Color,我想将其转换为’hex值’。 到目前为止,我还没有找到解决问题的方法。 我的代码如下: foreach (var cell in Grid.Children) { var pixel = new Pixel { XAttribute = cell.X , YAttribute = cell.Y , // I want to convert the color to a hex value here Color = cell.BackgroundColor }; }

Xamarin – 从base64字符串显示图像

我是Xamarin和XAML的新手,这是我迄今为止在Android和iPhone使用的便携式项目中所做的事情(仅使用Android): Item.cs(从JSON加载) [JsonProperty(“image”)] private string ImageBase64 { get; set; } [JsonIgnore] private Xamarin.Forms.Image _image = null; [JsonIgnore] public Xamarin.Forms.Image Image { get { if (_image == null) { _image = new Xamarin.Forms.Image() { Source = Xamarin.Forms.ImageSource.FromStream(() => new MemoryStream(Convert.FromBase64String(ImageBase64))), BackgroundColor = Color.White, WidthRequest = 64, HeightRequest = 64, }; OnPropertyChanged(“Image”); } return _image; } private […]

将位图保存到文件 – Xamarin,Monodroid

我正在尝试将位图图像保存到手机内的目录(图库)中。 该应用程序正在Xamarin中开发,因此代码是C#。 我似乎无法弄清楚如何创建目录,并保存位图。 有什么建议? public void createBitmap(View view){ view.DrawingCacheEnabled = true; view.BuildDrawingCache (true); Bitmap m_Bitmap = view.GetDrawingCache(true); String storagePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; Java.IO.File storageDirectory = new Java.IO.File(storagePath); //storageDirectory.mkdirs (); //save the bitmap //MemoryStream stream = new MemoryStream (); //m_Bitmap.Compress (Bitmap.CompressFormat.Png, 100, stream); //stream.Close(); try{ String filePath = storageDirectory.ToString() + “APPNAME.png”; FileOutputStream fos = new FileOutputStream (filePath); […]

HttpClient.GetAsync永远不会在Xamarin.Android上返回

我正在开发一个Android应用程序,由Azure上托管的ASP.NET Core应用程序提供支持。 在为Xamarin.Forms(仅限Android)项目制作function之前,我正在使用共享库项目来测试控制台应用程序项目的基本内容。 登录到Web服务后运行以下代码,其中Client是HttpClient : public static async Task GetInformationAsync(string accountId) { HttpResponseMessage response = await Client.GetAsync(UriData + “/” + accountId); response.EnsureSuccessStatusCode(); string responseContent = await response.Content.ReadAsStringAsync(); return JsonConvert.DeserializeObject(responseContent); } 在同一台计算机/网络下,代码在Console应用程序上完成不到一秒钟,然而,它在Xamarin.Forms.Android项目中永远不会完成(甚至等待一分钟)。 我发现这很奇怪,因为Android客户端可以使用PostAsync成功登录到Web服务。 但是,Android客户端和控制台客户端如何调用GetInformationAsync 。 而Console客户端异步调用它: private static async void TestDataDownload() { … var data = await WebApiClient.GetInformationAsync(myId); } Android客户端同步调用它 public void MainPage() { … var […]

Xamarin WebView – 在剃刀中没有Intellisense

我正在尝试使用xamarin webView,你可以使用剃刀视图作为UI。 但是C#代码的智能感知不起作用。 这是一个已知的错误还是我错过了什么? 我是否需要在webConfig文件中进行配置? 代码工作和构建,但是当我需要razor intellisense中的模型时将无法工作: @model TestProject.Models.Model1 testProject @Model.Text 在我写@model和@Model ,它只是说“无法解析符号……” 该怎么办?

Xamarin中的重叠如何形成?

z-index的概念是什么? 图为没有重叠。 如何设置z-index? 前两个自定义选择框 其余的都是。 图表,数据等 … BoxSelector.xaml(内容视图),可重用的ContentView扩展 #f9f9f9 #e2e2e2

在Xamarin.Forms中绑定自定义视图

我在将Xamarin表单中的自定义视图中的数据绑定到包含页面的视图模型时遇到问题。 我的自定义视图非常简单,一对代表键值对的标签: 后面的代码: public partial class KeyValueView : ContentView { public KeyValueView() { InitializeComponent(); this.VerticalOptions = LayoutOptions.Start; this.BindingContext = this; } public static readonly BindableProperty ValueProperty = BindableProperty.Create(w => w.Value, default(string)); public string Value { get {return (string)GetValue(ValueProperty);} set {SetValue(ValueProperty, value);} } public static readonly BindableProperty KeyProperty = BindableProperty.Create(w => w.Key, default(string)); public string Key […]

为什么Task.WaitAll()不会阻塞或导致死锁?

在下面的示例中,使用了两个await调用。 为了获得性能,样本转换为Task.WaitAll() (实际上没有更快,但这只是一个例子)。 这是来自Android上使用Sqlite.Net的库中的代码,该方法从主UI线程上的OnResume()调用: public async Task SetupDatabaseAsync() { await CreateTableAsync(); await CreateTableAsync(); } 这是替代方案: public void SetupDatabaseAsync() { var t1 = CreateTableAsync(); var t2 = CreateTableAsync(); Task.WaitAll(t1, t2); } 但是根据我的理解, Task.WaitAll()应该在等待时阻止UI线程,从而导致死锁。 但它的工作正常。 那是因为这两个调用实际上并没有在UI线程上调用任何东西吗? 如果我使用Task.WhenAll()而不是有什么区别? 我猜它即使调用UI线程也能工作,就像await 。

如何获取当前位置或移动到Xamarin.Forms.Map中的当前位置

由于Map已经显示了用户位置(使用IsShowingUser),我只想缩放到此位置。 这很容易实现,还是我需要在每个平台上获取位置,因为我找不到任何GeoLocation对象。 只有GeoCoder ……这不是缩放到用户位置的常用用例吗?