小编J. *_*non的帖子

如果没有GetAwaiter方法,我可以等待吗?

我看到一些关于设计自定义等待类型的文章:

http://books.google.com.br/books?id=1On1glEbTfIC&pg=PA83&lpg=PA83&dq=create+a+custom+awaitable+type

现在考虑以下示例:

<Button x:Name="BtnA"
        Width="75"
        Margin="171,128,0,0"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        Click="BtnA_Click"
        Content="Button A" />
<Button x:Name="BtnB"
        Width="75"
        Margin="273,128,0,0"
        HorizontalAlignment="Left"
        VerticalAlignment="Top"
        Content="Button B"  Click="BtnB_OnClick" />
Run Code Online (Sandbox Code Playgroud)

和:

private async void BtnA_Click(object sender, RoutedEventArgs e)
{
    MessageBox.Show("Awaiting Button B..");

    var sx = Observable.FromEvent<MouseButtonEventHandler, 
                                  MouseButtonEventArgs>(a => (b, c) => a(c),
                                  add => BtnB.PreviewMouseDown += add,
                                  rem => BtnB.PreviewMouseDown -= rem)
       .Do(a => a.Handled = true)
       .Take(1);

    await sx;

    MessageBox.Show("Button B Pressed after Button A");
}

private void BtnB_OnClick(object sender, RoutedEventArgs e)
{
    MessageBox.Show("Button B Pressed …
Run Code Online (Sandbox Code Playgroud)

.net c# system.reactive async-await

7
推荐指数
1
解决办法
8250
查看次数

如何在Asp.Net MVC 6中检索AppSettings配置?

假设我使用新的DepencyInjection框架在新的ASP.Net/vNext中配置我的类和依赖项.

我该如何使用,如何获取预定义的配置设置?

    public void ConfigureServices(IServiceCollection services)
    {
        // Add Application settings to the services container.
        services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));

        // Add EF services to the services container.
        services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
        // Add Identity services to the services container.
        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

        // Configure the options for the authentication middleware.
        // You can add options for Google, Twitter and other middleware as shown below.
        // For more information see http://go.microsoft.com/fwlink/?LinkID=532715
        services.Configure<FacebookAuthenticationOptions>(options =>
        {
            options.AppId = Configuration["Authentication:Facebook:AppId"];
            options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
        });

        services.Configure<MicrosoftAccountAuthenticationOptions>(options …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection appsettings asp.net-core-mvc

7
推荐指数
1
解决办法
2837
查看次数

跨平台应用程序WPF,ASP.NET,Silverlight,WP7,XAML

考虑到所有应用程序都将与Web项目(将使用云或Web服务)进行交互这一事实.有没有办法在应用程序之间共享我的类模型?

如果是的话,最好的方法是什么?

关于从Webservice发送/接收数据,序列化和反序列化,如何以简单的方式执行此操作而无需手动填充对象?

有关此应用程序的任何信息都非常有用!

.net c# asp.net wpf design-patterns

6
推荐指数
1
解决办法
1290
查看次数

等待方法中的取消令牌

将令牌放在任务的构造函数中的原因很多,如下所述: 任务构造器中的取消令牌:为什么?

通过使用关键字async / await,它如何工作?例如下面的代码:

public async Task MethodAsync(CancellationToken token)
{
  await Method01Async();
  await Method02Async();
}
Run Code Online (Sandbox Code Playgroud)

虽然这是一个异步过程。我很快就使用了“ Task.StartNext”或“ Task.Run”或“新任务”。为了能够指定我的取消令牌,该怎么办?

c# async-await async-ctp cancellation-token

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

MethodBase.GetCurrentMethod().Name vs [CallerMemberName]

有什么区别和对代码的影响?

性能和限制如何,哪种更适合?

新属性:
- [CallerFilePathAttribute]
- [CallerMemberName]
- [CallerLineNumber]

今天它们也可以在.NET 4中使用(它易于开发并且看起来很神奇).它们的值在运行时被编译或解析?

.net c# reflection compiler-services

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

彩色动画ContentPresenter

我无法在ContentPresenter(NormalTextDay)中创建动画或自定义颜色,此错误出现在我的XAML中:

'System.Windows.Media.Animation.ColorAnimation'动画对象不能用于动画属性'Foreground'它是因为不兼容的类型'System.Windows.Media.Brush

  <Style x:Key="CalendarDayButtonStyle" TargetType="{x:Type CalendarDayButton}">
    <Setter Property="MinWidth" Value="5"/>
    <Setter Property="MinHeight" Value="5"/>
    <Setter Property="FontSize" Value="10"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type CalendarDayButton}">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Pressed">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <!--<Storyboard>
                                    <DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
                                    <DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="NormalText"/>
                                </Storyboard>-->
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0"/>
                            </VisualStateGroup.Transitions>
                            <VisualState …
Run Code Online (Sandbox Code Playgroud)

wpf animation colors contentpresenter visualstates

2
推荐指数
1
解决办法
6448
查看次数

将项目转换为.Net 4.5(使用TPL)

目前拥有.net 3.5和.net 4.0的一些项目.
决定将所有迁移到.NET 4.5.

所有项目都已在VS2012(C#5.0)中,所有项目都使用async-await关键字

正在使用.net 4.0项目正在使用Microsoft.Bcl.Async
On .net 3.5项目正在使用AsyncBridge.Net35和TaskParallelLibrary

问题是:
- .net 4.5中没有TaskEx类和其他扩展方法,或者我不知道这些是否存在

如何在不对代码进行重大更改的情况下进行此更改?

.net c# base-class-library async-await

2
推荐指数
1
解决办法
1184
查看次数

如何在不改变基于当前位置X和Y的纵横比的情况下调整旋转控件的大小?

目前我使用了以下代码,它工作正常,但不尊重宽高比:

    private double angle;
    private Point transformOrigin;
    private ContentControl designerItem;

    public ResizeThumb()
    {
        DragStarted += new DragStartedEventHandler(this.ResizeThumb_DragStarted);
        DragDelta += new DragDeltaEventHandler(this.ResizeThumb_DragDelta);
    }

    private void ResizeThumb_DragStarted(object sender, DragStartedEventArgs e)
    {
        this.designerItem = DataContext as ContentControl;

        if (this.designerItem != null)
        {
            this.transformOrigin = this.designerItem.RenderTransformOrigin;
            RotateTransform rotateTransform = this.designerItem.RenderTransform as RotateTransform;
            if (rotateTransform != null)
                this.angle = rotateTransform.Angle * Math.PI / 180.0;
            else
                this.angle = 0;
        }
    }

    private void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
    {
        if (this.designerItem != null)
        {
            double deltaVertical, deltaHorizontal; …
Run Code Online (Sandbox Code Playgroud)

c# wpf controls transform

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

LINQ orderby来自特定值

样品:

var aux = new int[] { -1,0,1,-1,2,3,4,5,6,7 } 
Run Code Online (Sandbox Code Playgroud)

预期结果:

{ 2,3,4,5,6,7,1,0,-1,-1 }
Run Code Online (Sandbox Code Playgroud)

怎么样?

-

编辑:抱歉这个糟糕的问题.我想从值2和其他放在较低端的人(我修复文本)中订购所有.

c# linq sorting sql-order-by

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