小编Ewa*_*wan的帖子

StackLayout宽度计算中的RelativeLayout

我有与嵌套在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)

屏幕截图

xaml android xamarin xamarin.forms

10
推荐指数
1
解决办法
2513
查看次数

创造一个等待冷酷的任务

我完成后有一个异步方法,我想运行另一个方法.如果我只是调用方法并添加.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)

c# task-parallel-library async-await

9
推荐指数
1
解决办法
1303
查看次数

使用填充居中布局 - 舍入错误

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)

xamarin xamarin.forms

5
推荐指数
1
解决办法
146
查看次数

如何使用 OWIN Jwt Bearer 身份验证记录身份验证结果

我想记录对我的 .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

https://github.com/aspnet/Security/blob/ba1eb281d135400436c52c17edc71307bc038ec0/src/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerHandler.cs#L63-L83

编辑2:非常令人沮丧。看起来应该是正确的登录位置Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter但是这是在您使用时自动添加的[Authorize] …

c# jwt owin asp.net-core-mvc .net-core

5
推荐指数
2
解决办法
3109
查看次数

AbsoluteLayout不填充屏幕

我在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)

在6.0.0上1px白线(你必须放大)

在这个例子中,我使用boxview填充屏幕,但它的任何排列位置都与屏幕底部对齐.

我正在寻找的是某种变通方法或自定义渲染器,它将确保以1,1拉伸或拉伸整个屏幕高度的项目放置在屏幕底部或伸展到屏幕底部

android xamarin xamarin.forms

4
推荐指数
1
解决办法
4735
查看次数