小编Fra*_*Liu的帖子

更新ObservableCollection中的项目时更新ItemsControl

问题:

  • 您在视图中声明ItemsControl(或从中派生的控件ItemsControl).
  • 您将ItemsControl.ItemsSource属性绑定到ObservableCollectionViewModel中的a.
  • 当项目被添加到/从中删除时,您的视图会按预期更新ObservableCollection.
  • 但是,当您更改项目中的项目的属性时,视图不会更新ObservableCollection.

背景:

这似乎是许多WPF开发人员遇到的常见问题.有人问过几次:

项目更改时通知ObservableCollection

ObservableCollection没有注意到它中的Item何时发生变化(即使使用INotifyPropertyChanged)

ObservableCollection和Item PropertyChanged

我的实施:

当Item更改时,我尝试在Notify ObservableCollection中实现接受的解决方案.基本思想是PropertyChanged在MainWindowViewModel中为每个项目连接一个处理程序ObservableCollection.更改项目的属性时,将调用事件处理程序,并以某种方式更新视图.

我无法让实现工作.这是我的实施.

的ViewModels:

class ViewModelBase : INotifyPropertyChanged 
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void RaisePropertyChanged(string propertyName = "")
    {
        var handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
}
Run Code Online (Sandbox Code Playgroud)

项目视图模型:

class EmployeeViewModel : ViewModelBase
{
    private int _age;
    private string _name;

    public int Age 
    { …
Run Code Online (Sandbox Code Playgroud)

c# wpf itemscontrol observablecollection mvvm

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

带有重载成员函数的C++ std :: mem_fn

编译以下代码时,Visual Studio报告:

\main.cpp(21): error C2664: 'std::_Call_wrapper<std::_Callable_pmd<int ClassA::* const ,_Arg0,false>,false> std::mem_fn<void,ClassA>(int ClassA::* const )' : cannot convert argument 1 from 'overloaded-function' to 'int ClassA::* const '
    1>          with
    1>          [
    1>              _Arg0=ClassA
    1>          ]
    1>          Context does not allow for disambiguation of overloaded function
Run Code Online (Sandbox Code Playgroud)

编译时为什么编译器会混淆mem_fptr1?但是mem_fptr2当我指定类型时,有些可以.

我可以创建成员函数指针指向不带参数的重载成员函数吗?

class ClassA
{
public:
    void memberfunction()
    {
        std::cout <<"Invoking ClassA::memberfunction without argument" << std::endl;
    }

    void memberfunction(int arg)
    {
        std::cout << "Invoking ClassA::memberfunction with integer " << arg << std::endl;
    } …
Run Code Online (Sandbox Code Playgroud)

c++ function-pointers c++11

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

将Angular 2 App部署到Azure

我正在学习Angular 2和Azure.我遵循了Angular 2 Tutorial,一切都在本地运行良好.

我将应用程序发布到Azure.该出版物成功了.但是当我访问该网站时,它仍处于加载阶段.查看Chrome控制台中的日志,我看到以下错误./app/main.ts找不到该文件.

在此输入图像描述

我按照此问题的建议通过"Kudu"仪表板检查了我部署的文件.我没有看到任何*.ts只部署*.js*.map.

在此输入图像描述

然后我回到Visual Studio将所有*.ts文件的属性更改为Copy Always.更改后,我可以看到*.ts文件被复制到.\bin\app目录中.但是,在我将项目重新发布到Azure(再次成功)后,我仍然在请求main.ts文件时遇到404错误.

根据这个问题, IIS无法正确提供Typescript文件.

首先:如何在Azure上应用建议的更改来修复它?

其次:为什么我们需要使用这些*.ts文件?根据我的理解,*.ts遵守*.js.为什么我们不能只请求*.js正确部署到Azure 的文件?

azure typescript angular

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

单元测试在调试版本中传递,但在版本构建中失败

我为异步类成员编写了一个单元测试.当我在"Debug build"下执行测试时,测试按预期传递.但是,当我在"Release build"下执行我的测试时,它会挂起CPU(当循环死锁时).

如果我使用Debug构建(即Debug构建单元测试程序集和Release构建目标程序集)专门配置Unit测试项目,那么测试也会通过.

要测试的代码

    public override void DoSomething(object parameter)
    {
        ThreadPool.QueueUserWorkItem(AsyncDoSomething, parameter);
    }

    private void AsyncDoSomething(object parameter)
    {
        //Doing something
                .....

        //Something is done
        RaiseSomethingIsDone();
    }
Run Code Online (Sandbox Code Playgroud)

我的单元测试

    public void DoingSomethingTest()
    {
        bool IsSomethingDone = false;

        //Setup
        //Doing some setup here.
        target.SomethingDone += (sender, args) =>
            {
                IsSomethingDone = true;
            };

        //Exercise
        target.DoSomething(_someParameter);
        while (!IsSomethingDone ){}

        //Verify
        //Doing some asserts here.
    }
Run Code Online (Sandbox Code Playgroud)

这是在调试配置和发布配置下由C#编译器生成的IL:

调试while循环IL interpenetration:

  IL_00cb:  ldloc.s    'CS$<>8__locals7'
  IL_00cd:  ldfld      bool IsSomethingDone
  IL_00d2:  ldc.i4.0
  IL_00d3:  ceq
  IL_00d5:  stloc.s    CS$4$0001
  IL_00d7: …
Run Code Online (Sandbox Code Playgroud)

c# multithreading unit-testing

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

在部署Angular 2项目时,Azure持续部署与Github失败

我是Azure和Angular2的新手.

目标

使用GitHub设置Azure持续部署.

问题

Azure正在获取存储库主分支的提交.所以这部分还可以.但是,由于生成错误,部署失败.

这是部署详细信息:

在此输入图像描述

这是完整的日志:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin'.
All packages listed in packages.config are already installed.
D:\home\site\repository\LearnJS\LearnJS.Web\app\app.component.ts(1,41): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\app.component.ts(2,46): error TS2307: Build: Cannot find module 'angular2/router'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis-form.component.ts(1,25): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis-form.component.ts(2,22): error TS2307: Build: Cannot find module 'angular2/common'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.component.ts(1,33): error TS2307: Build: Cannot find module 'angular2/core'. [D:\home\site\repository\LearnJS\LearnJS.Web\LearnJS.Web.csproj]
D:\home\site\repository\LearnJS\LearnJS.Web\app\crisis.component.ts(2,30): error TS2307: …
Run Code Online (Sandbox Code Playgroud)

github azure node.js continuous-deployment angular

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

Linux Xwindow转发上的Visual Studio代码

我的配置如下:

OS:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.4 LTS"
NAME="Ubuntu"
VERSION="14.04.4 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.4 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
Run Code Online (Sandbox Code Playgroud)

Visual Studio代码 1.5.3

Xming的 6.9.0.31

为了安装visual studio代码,我不得不跳了很多箍.最后,我设法做到了.我跑的时候

code 要么 code .

它立即返回到命令行,没有错误.

然后我跑了

code --verbose
Run Code Online (Sandbox Code Playgroud)

我收到以下消息.

OpenGL Warning:
XComposite not found or old version (0.0), no VisibilityTracking
{ [Error: ENOENT: no such file or directory, open '/home/vagrant/.config/Code/storage.json']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/home/vagrant/.config/Code/storage.json' }
(5:08:07 AM) ### VSCode main.js ###
(5:08:07 AM) /usr/share/code/resources/app { …
Run Code Online (Sandbox Code Playgroud)

linux visual-studio

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

如何使用Entity Framework打开受密码保护的SQL Server CE数据库

我使用的是EF 6.0和SQL Server CE 4.0.该.sdf文件受密码保护,我通过LinqPad打开文件验证了该文件.当我尝试使用以下连接字符串在代码中打开此数据库时,我得到一个异常:

指定的密码与数据库密码不匹配

码:

using (var context = new MyDbContext("ExamManagement"))
{
    context.Database.Initialize(false);
}
Run Code Online (Sandbox Code Playgroud)

连接字符串:

<connectionStrings>
    <add name="ExamManagement" 
         connectionString="Data Source=|DataDirectory|Pikeman.sdf;Max Database Size=4091;Password=123;" 
         providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 堆栈跟踪:

位于System.Data.Entity.Core.EntityClient.EntityConnection.Open()
处于System.Data.Entity.Core.Object.Entity上的System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
中的System.Data.Entity. ](Func键1.<> c__DisplayClass7.b__5() 在System.Data.Entity.Core.Objects.ObjectQuery 1 forMergeOption) 在System.Data.Entity.Core.Objects.ObjectQuery 1.MoveNext() 在System.Linq.Enumerable .First [TSource](IEnumerable`1 source) 1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery

1.GetResults(Nullable
1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator

entity-framework sql-server-ce

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

Angularjs 2组件属性未定义

我一直在关注Angular 2开发指南.我在做9路由和导航里程碑3时遇到了这个问题

我添加了一个getCrisis带一个参数的函数sn.该函数Promise<Crisis>异步返回.

crisis.service.ts

import {Injectable} from 'angular2/core';
import {CRISES} from './mock-crisises';

@Injectable()
export class CrisisService {

    getCrisises() {
        return Promise.resolve(CRISES);
    }

    // the | string token is a Pipe
    getCrisis(sn: number | string) {
        return Promise.resolve(CRISES).then(cries => cries.filter(c => c.serialNumber === +sn)[0]);
    }
}
Run Code Online (Sandbox Code Playgroud)

危机form.component.ts调用getCrisisngOnInit

export class CrisisFormComponent implements OnInit, CanDeactivate{

    public model: Crisis;
    public origin: Crisis;

    submitted = false;
    active = true;

    constructor(
        private _service: CrisisService, …
Run Code Online (Sandbox Code Playgroud)

angular

4
推荐指数
2
解决办法
9079
查看次数

多核系统上的C++多线程

在四核CPU上运行以下代码时,我保证这四个线程将在四个不同的内核上运行吗?

或者操作系统可以根据系统的工作负载在单个核心上放置多个线程.如果是这种情况,由于上下文切换和其他线程开销,运行多线程甚至可能会给您带来性能损失.

我想没有办法对应用程序进行编码,这会强制线程在不同的内核上运行?

int main()
{
    std::vector<std::thread> threads(3);

    for (size_t i = 0; i < 3; i++)
    {
        threads[i] = std::thread(DoSomethingLengthy);
    }

    DoSomethingLengthy();

    for (auto& thread : threads)
    { 
        thread.join(); 
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ multithreading

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