小编Mah*_*ahi的帖子

如何使用 C# 在 Winforms 中制作自定义 Toast 窗口通知

我试图在计时器用完给定时间后显示 toast 通知,用户可以通过单击该通知 UI 的任何位置来关闭它。我可以通过使用默认通知控件来完成此操作,但我想使用基于通知类型的自定义图标和声音。使用默认通知控件在 Windows 10 中工作正常,但 Windows 7 通知看起来不太好。所以我需要一个通用的实现,以便所有 Windows 操作系统(7、\xc2\xa08、\xc2\xa010)正确显示它。

\n\n

这是一个屏幕截图,以便更好地理解。

\n\n

示例通知

\n

c# notifications toast winforms

6
推荐指数
0
解决办法
3715
查看次数

我需要在 ASP.Net core Web API 的验证属性中返回自定义的验证结果(响应)

我需要在 ASP.Net core Web API 中返回自定义的验证结果(响应)失效属性,这是我创建的 ValidationAttribute。

class MaxResultsAttribute : ValidationAttribute
{
    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        int maxResults = (int)value;

        if (maxResults <= 0)
        {
            return new CustomValidationResult(new ValidationResult("MaxResults should be greater than 0"));
        }

        return ValidationResult.Success;
    }
}
Run Code Online (Sandbox Code Playgroud)

我创建了继承 ValidationResult 的 CustomValidationResult 对象,以便我可以返回我自己的自定义响应:

public class CustomValidationResult : ValidationResult
{
    public int FaultCode { get; set; }

    public string FaultMessage { get; set; }

    public CustomValidationResult(ValidationResult validationResult) : base(validationResult)
    {
        FaultCode = 123;
        FaultMessage = validationResult.ErrorMessage; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net validationattribute asp.net-web-api asp.net-core

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

如何安全地用 getServerSideProps / getStaticProps 替换 getInitialProps

下面这句话大家都很熟悉:You should not use getInitialProps, but getServerSideProps instead. 我已经使用构建了我的应用程序getInitialProps,现在我面临以下问题:“我是否应该将 getInitialProps 替换为 getServerSideProps?”,如果是这样,我应该如何以正确的方式进行操作而不损坏我的应用程序?

今天,我getInitialProps在几个重要的地方使用:

  1. 在我的习惯_app.jsreact-redux
class MyApp extends App {
    static async getInitialProps({ Component, ctx }) {
        return {
            pageProps: {
                ...(Component.getInitialProps
                    ? await Component.getInitialProps(ctx)
                    : {})
            }
        };
    }

    render() {
        const { Component, pageProps, store } = this.props;
        return (
            <>
                <Provider store={store}>
                    <Component {...pageProps} />
                </Provider>
            </>
        );
    }
}

export default withRedux(initStore)(withReduxSaga(MyApp));
Run Code Online (Sandbox Code Playgroud)
  1. 在页面的一些 HOC 中:检查用户是否通过身份验证(否则重定向),如果用户通过身份验证,则初始化 redux 存储,获取用户信息。 …

next.js getserversideprops

5
推荐指数
0
解决办法
594
查看次数