在我的Xamarin.Forms应用程序中,我有一个自定义视图:
[Xamarin.Forms.ContentProperty("Content")]
public class Checkbox : ContentView
{
Label lbl = new Label() { Text = "\u2610" }; // \u2610 Uni code will show empty box
Label lbl1 = new Label() { Text = "Has arrived" };
public string BackgroundColor { get; set; }
public Checkbox()
{
TapGestureRecognizer t = new TapGestureRecognizer();
t.Tapped += OnTapped;
StackLayout stackLayout = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
HorizontalOptions = LayoutOptions.StartAndExpand,
Children = {lbl,lbl1}
};
stackLayout.GestureRecognizers.Add(t);
Content = stackLayout;
}
public void OnTapped(object sender, …
Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio 2013和.NET framework 4.5.1版
我正在阅读有关Reactive Extensions的教程,我正在尝试运行此代码:
var t = Task.Factory.StartNew(() => "Test");
var source = t.ToObservable();
Run Code Online (Sandbox Code Playgroud)
t.ToObservable()
加下划线并给我错误
System.Threading.Tasks.Task <.string>不包含ToObservable的定义...
我在另一篇文章中读到,我应该下载Silverlight Toolkit并将System.Reactive.dll
其作为参考包含在内,但这并没有帮助.
我该怎么做才能解决这个问题?
我有一个要包装的函数,以便可以使用async / await模式:
wcfClientService.GetSomeString(parameter);
Run Code Online (Sandbox Code Playgroud)
这是来自WCF客户端的呼叫,我正在尝试使其异步,但这并不重要(我知道WCF支持异步,但是假设我们无权访问WCF代码)。
我正在尝试用该Task<T>.Factory.FromAsync
方法包装该方法,但似乎无法正确处理它:
private Task<string> WrapWcfServiceAsyncTask(uint parameter)
{
Func<uint, string> func = i => { return wcfClientService.GetSomeString(parameter); };
var t = Task<string>.Factory.FromAsync(
// What goes here?
);
return t;
}
Run Code Online (Sandbox Code Playgroud)
甚至更好的是,有人可以编写一个将方法作为参数并包装并Task<T>
为其返回的方法吗?
我正在使用Visual Studio for Mac.我在我的项目中安装了MvvmCross v5.1.1.我想将它(及其所有依赖项和插件)更新到v.5.3.1.但是当我尝试更新我的包时,我在输出中收到此错误消息:
无法解析依赖项.'MvvmCross.Binding 5.3.1'与'MvvmCross.Droid.Shared 5.1.1约束:MvvmCross.Binding(= 5.1.1)'不兼容.
我最近发现我应该将所有尺寸/尺寸都放在dimens.xml
我想要支持多种屏幕分辨率的 Android 应用程序中。
我应该在 iOS 中做类似的事情来支持多种屏幕分辨率吗?我的代码我在后端的所有视图(无故事板),当我想要放置一个视图(填充,利润等),我只是在添加硬编码的数字X
和Y
视图的属性frame
。对于Width
, Height
,Font size
等来说也是如此。我想我这样编码的 iOS 应用程序在像这样的不同屏幕分辨率下看起来会很尴尬吗?
顺便说一下,我正在使用 Xamarin(Xamarin.Android 和 Xamarin.iOS)。但我会使用本机代码理解答案。
我正在编写 Xamarin.Forms 应用程序。它之前还可以工作,但现在它在我的 Android 项目的这一行上抛出异常:
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
Run Code Online (Sandbox Code Playgroud)
它抛出异常:
System.TypeInitializationException:“MyApp.Core.App”的类型初始值设定项引发异常。
构造函数甚至不会被调用。我什至不知道我做了什么导致这个......有没有人有任何想法?
这是我的 App.xaml.cs 代码
public partial class App : Application
{
public static INavigation Navigation
{
get;
set;
}
public static Lazy<LoungeListPage> LoungeListView { get; set; } = new Lazy<LoungeListPage>();
public static Lazy<LoungePage> LoungeView { get; set; } = new Lazy<LoungePage>();
public static Lazy<EditFencePage> FenceView { get; set; } = new Lazy<EditFencePage>();
public static Lazy<NewFencePage> NewFenceView { get; set; } = new Lazy<NewFencePage>();
public static ILoungeService LoungeService { get; …
Run Code Online (Sandbox Code Playgroud) 在我的 Xamarin.Forms 应用程序中,我想以Frame
编程方式创建一个视图并将其作为子视图添加到其中:
var child = new Label()
var frame = new Frame();
// How do I add child to frame?
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
在我的 Xamarin.Forms 应用程序中,我正在编写本机 Android 代码来宣传 UUID 和一些测试数据,以便另一台设备扫描并找到它。我正在平板电脑 SM-T580 上运行该应用程序。这是我的代码:
var parameters = (new AdvertiseSettings.Builder())
.SetAdvertiseMode(AdvertiseMode.Balanced)
.SetConnectable(false)
.SetTimeout(0)
.SetTxPowerLevel(AdvertiseTx.PowerMedium).Build();
AdvertiseData data = (new AdvertiseData.Builder()).AddServiceData(_applicationParcelUuid,
System.Text.Encoding.ASCII.GetBytes("helloTest123"))
.Build();
if (BluetoothAdapter.DefaultAdapter.BluetoothLeAdvertiser != null)
{
BluetoothAdapter.DefaultAdapter.BluetoothLeAdvertiser.StartAdvertising(parameters, data, _customAvertiseCallback);
}
Run Code Online (Sandbox Code Playgroud)
在我_customAvertiseCallback
的OnStartSuccess
覆盖被调用,所以我认为它应该工作。我尝试在 Nexus 5 设备上使用 nRF Connect 应用程序对其进行测试,但我从未在其上看到我的设备的广告。
编辑
我尝试添加扫描 BLE 广告的代码,看看我是否可以自己捡起它。它会从其他设备中找到其他 BLE 广告,但不会从我的应用中找到。这是我的扫描代码,它运行在同一个应用程序上:
public void StartBluetoothScanning()
{
if(_bleScanningInitialized)
{
return;
}
/**
* Initialize BluetoothAdapter
* Check the device has the hardware feature BLE
* Then enable the hardware,
*/
BluetoothManager bluetoothManager …
Run Code Online (Sandbox Code Playgroud) 在我的 Web Api 应用程序中,我有控制器:
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
System.Diagnostics.Trace.TraceInformation("in get...");
return "value";
}
}
Run Code Online (Sandbox Code Playgroud)
我希望在发布日志时能够在 Azure 上看到“in get...”日志。在 Azure 上,在App Service Logs
I 打开Application Logging (Filesystem)
并将级别设置为Information
。在 中Log Stream
,当我转到该方法的 url 时,我在日志中看到:
正在连接... 2020-02-09T06:07:38 欢迎,您现在已连接到日志流服务。默认超时为 2 小时。使用应用程序设置 SCM_LOGSTREAM_TIMEOUT 更改超时(以秒为单位)。2020-02-09 06:08:07.158 +00:00 [信息] Microsoft.AspNetCore.Hosting.Internal.WebHost:请求启动 HTTP/1.1 GET http://testapi20200208104448.azurewebsites.net/api/values/5 2020- …
直到今天早上,我都能在物理设备和模拟器上正常调试 Xamarin.iOS 应用程序。我认为这与最近的iOS更新有关。当我尝试部署到我的物理设备 (iPad) 时,我现在收到以下消息:
错误 HE0003:无法加载框架“IBFoundation”(路径:/Applications/Xcode.app/Contents/Frameworks/IBFoundation.framework/IBFoundation):找不到。
我无法再在任何模拟器上部署,我收到此消息
降低部署目标以查看较旧的模拟器或检查 Apple SDK 路径
我昨天没有遇到这些问题,而且我已经在我的应用程序上工作了几个月,没有出现这个问题。我更新了 Visual Studio、Xcode 和我的 Mac,但这些问题仍然存在。知道如何修复吗?
c# ×3
xamarin ×3
.net ×2
android ×2
async-await ×1
azure ×1
ios ×1
mvvmcross ×1
task ×1
xamarin.ios ×1