我有与嵌套在StackLayout RelativeLayouts一个奇怪的问题,看来StackLayout计算其元素的宽度应该使用RelativeLayout的宽度,然后再RelativeLayout的重新计算它之后.这导致子控件是相对宽度的平方,但是以下控件被放置为相对宽度.
这是一个错误还是我做错了什么?
例
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="MyClass"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
>
<StackLayout Orientation="Horizontal" BackgroundColor="Blue">
<RelativeLayout>
<ContentView BackgroundColor="Red"
RelativeLayout.XConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=0}"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=0.707106}"
RelativeLayout.YConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=0}"
RelativeLayout.HeightConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=1}">
</ContentView>
</RelativeLayout>
<RelativeLayout>
<ContentView BackgroundColor="Green"
RelativeLayout.XConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=0}"
RelativeLayout.WidthConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Width,
Factor=0.5}"
RelativeLayout.YConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=0}"
RelativeLayout.HeightConstraint=
"{ConstraintExpression Type=RelativeToParent,
Property=Height,
Factor=1}">
</ContentView>
</RelativeLayout>
</StackLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
我完成后有一个异步方法,我想运行另一个方法.如果我只是调用方法并添加.ContinueWith(),这可以正常工作
但是,我有一个新的要求,即只有在我能够将它添加到并发字典时才启动任务.
我希望构建任务,尝试添加它,然后启动任务
但是,似乎Task.Start()立即完成任务,导致继续操作运行,任何等待...等待.
谁能解释为什么会发生这种情况以及实现目标的正确方法?
namespace UnitTestProject2
{
[TestClass]
public class taskProblem
{
[TestMethod]
public void Test()
{
CancellationTokenSource cancel = new CancellationTokenSource();
ConcurrentDictionary<Guid, Task> tasks = new ConcurrentDictionary<Guid,Task>();
Guid id = Guid.NewGuid();
Task t = new Task(async () => await Get(), cancel.Token);
t.ContinueWith(Complete);
if (tasks.TryAdd(id, t))
{
t.Start();
}
else
{
//another thread is stopping stuff dont start new tasks
}
t.Wait(); //expected to wait for the get function to complete
Console.WriteLine("end test");
}
public async Task Get()
{ …Run Code Online (Sandbox Code Playgroud) xamarin中的嵌套布局似乎偏向屏幕左侧.我假设这是一个dp到像素舍入偏差或什么?
任何人都可以确认,是否有解决方案或解决方案?
虽然我的示例使用绝对布局,但问题似乎出现在所有布局上.
using System;
using Xamarin.Forms;
namespace XamarinTest
{
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
AbsoluteLayout child = layout;
AbsoluteLayout.SetLayoutFlags(child, AbsoluteLayoutFlags.All);
AbsoluteLayout.SetLayoutBounds(child, new Rectangle(0, 0, 1, 1));
Random rand = new Random();
for (int i =0;i<100; i++)
{
child = addLayout(child, rand) ;
}
AbsoluteLayout abs = new AbsoluteLayout();
AbsoluteLayout.SetLayoutFlags(abs, AbsoluteLayoutFlags.All);
AbsoluteLayout.SetLayoutBounds(abs, new Rectangle(0, 0, 0.5, 0.5));
abs.BackgroundColor = Color.Black;
layout.Children.Add(abs);
}
private AbsoluteLayout addLayout(AbsoluteLayout parent, Random rand)
{
AbsoluteLayout abs = new AbsoluteLayout(); …Run Code Online (Sandbox Code Playgroud) 我想记录对我的 .netcore webapi 的所有调用的统计信息。
我IAsyncActionFilter为此目的添加了一个,它可以处理所有操作。
但是我也启用了 Jwt Bearer 身份验证,并且正在使用AuthorizeAttribute我的控制器上的 来限制访问。当访问被拒绝时,将不会命中操作过滤器。
添加一些自定义日志记录 (statsd) 以进行一般身份验证和特别是失败的最佳方法是什么?
public void ConfigureServices(IServiceCollection services)
{
....
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
// base-address of your identityserver
options.Authority = Configuration["Authority"]; ;
// name of the API resource
options.Audience = "myAudience";
});
...
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseAuthentication();
...
}
Run Code Online (Sandbox Code Playgroud)
我注意到JwtBearerOptions有,JwtBearerEvents Events但我不能让它工作。
编辑:看起来我在访问 api 时根本没有令牌,JWT Auth 处理程序返回 AuthenticateResult.NoResult() 而不调用 Events.AuthenticationFailed
编辑2:非常令人沮丧。看起来应该是正确的登录位置Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter但是这是在您使用时自动添加的[Authorize] …
我在Android 6.0 Marshmellow上的Xamarin Forms中存在绝对布局问题
当设置视图以填满整个屏幕时,屏幕底部会留下1px的间隙.
奇怪的是,如果将屏幕旋转到横向,则不会发生这种情况.或者4.4
xaml:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinTest.Page1">
<AbsoluteLayout BackgroundColor="White">
<BoxView BackgroundColor="Red" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
</BoxView>
</AbsoluteLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
屏幕截图:(这些来自vs仿真器,但我也在设备上获得相同的行为,例如三星galaxy 6)
在这个例子中,我使用boxview填充屏幕,但它的任何排列位置都与屏幕底部对齐.
我正在寻找的是某种变通方法或自定义渲染器,它将确保以1,1拉伸或拉伸整个屏幕高度的项目放置在屏幕底部或伸展到屏幕底部