小编Vin*_*ent的帖子

数据绑定ContentControl过渡动画?

我有一个使用这种语法数据绑定的ContentControl:

<ContentControl  Content="{Binding Path=View}"></ContentControl>
Run Code Online (Sandbox Code Playgroud)

我使用命令替换View,并想知道在更改此属性时是否可以使用动画,例如从一个UserControl更改为另一个UserControl?

期待着听到您的意见.

谢谢,斯特凡

wpf animation

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

每次触发Form.Load事件

我想知道我是否做得正确.

我在我的类(也是一个表单)中实例化一个Form(让我们调用这个Form_B)并处理Form_B的Load事件.在这个事件中我做了一些初始化.

Form_B可以由用户多次显示,我在我的实例变量上调用ShowDialog.

问题是每次显示表单时都会调用Load.我尝试过调试,并尝试使用Show()而不是ShowDialog().Show()因关闭窗口而失败,但ShowDialog()没有失败,但每次显示时都调用Load.

表单关闭后继续使用实例是否不正确?

谢谢,斯特凡

c# windows events

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

在括号内捕获并按字符分割

我有这个正则表达式: {([^}]+)}

它成功捕获了括号内容,例如 hello {foo} and {bar}.

我还希望捕获由一个字符分隔的匹配内的组,例如 hello {foo:bar} and {hello:world}.

前者会{foo:bar}与群体产生匹配{foo},{bar}而后者则{hello:world}与群体{hello}和群体匹配{world}.

我不精通正则表达式,我已经试过这样:{([^}]+)(:([^}]))?}{([^}]+)(\:([^}]))?}万一:是一个特殊字符.

我需要做哪些修改才能成功?

c# regex

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

添加新包会破坏 .NET 5 应用程序

我一直试图找出为什么我的控制台应用程序在引入新包后立即失败。使用IdentityModel.OidcClientand有效,但添加时会引发异常。我也不在代码中引用新包,我只是将其添加到项目中。Microsoft.AspNetCore.Server.Kestrel Microsoft.Extensions.Configuration.Json

重现步骤:

  1. 克隆https://github.com/IdentityModel/IdentityModel.OidcClient.Samples.git

  2. 将NetCoreConsoleClient升级到 .NET 5(更新包)。

  3. 删除Serilog.Sinks.Literate过时的包。

  4. 在 Program.cs 中删除对 SeriLog 的调用.WriteTo.LiterateConsole并添加using IdentityModel.Client.

  5. 为类中的方法添加CancellationToken cancellationToken = new CancellationToken()参数。接口的签名已更改,新方法应如下所示:InvokeAsyncSystemBrowserIBrowserpublic async Task<BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = new CancellationToken())

  6. 运行应用程序并使用 alice/alice 登录。获取token成功。

  7. 添加包Microsoft.Extensions.Configuration.Json

  8. 运行应用程序。Object reference not set to an instance of an object现在写入 http 响应时会引发异常。

LoopbackHttpListener.SetResult写入响应时发生异常:ctx.Response.WriteAsync("<h1>You can now return to the application.</h1>");

为什么添加一个包会对运行时产生如此大的影响?

项目文件: …

c# kestrel-http-server identitymodel .net-5

3
推荐指数
1
解决办法
1090
查看次数

asp.net core mvc 2 中抽象类的模型绑定器

我一直在尝试为 ASP.NET Core 2 中的抽象类实现模型绑定程序,但没有成功。

我特别研究了两篇看起来非常好的文章:

http://www.dotnetcurry.com/aspnet-mvc/1368/aspnet-core-mvc-custom-model-binding

Asp 网络核心 rc2. 抽象类模型绑定

我有两个目标正在努力实现

  1. 根据模型的需要自动创建任意数量的嵌套编辑器(子嵌套)。
  2. 将表单值正确映射回模型。

这是我基于上述文章的代码。

public class Trigger
{
    public ActionBase Action { get; set; }
}

[ModelBinder(BinderType = typeof(ActionModelBinder))]
public abstract class ActionBase
{
    public string Type => GetType().FullName;

    public ActionBase Action { get; set; }
}

public class ActionA : ActionBase
{
    public int IntProperty { get; set; }
}

public class ActionB : ActionBase
{
    public string StringProperty { get; set; }
}

public class ActionModelBinderProvider : …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc asp.net-core asp.net-core-mvc-2.0

0
推荐指数
1
解决办法
2964
查看次数