2015-01-20 1 views
0

요소 초기화시 DependencyProperty을 어떻게 설정할 수 있습니까 ??요소의 초기화시 DependencyProperty를 설정 하시겠습니까?

new DataGrid() { FocusManager.SetIsFocusScope(DataGrid_Obj,true)}; 
그것은 나에게 다음과 같은 오류주고있다

: 나는 다음과 같이 작성하는 경우

enter image description here

을 :

DataGrid DataGrid_Obj = new DataGrid() { FocusManager.SetIsFocusScope(DataGrid_Obj,true)}; 

를 다음 그것은 나에게주고있다 :

enter image description here

답변

1

here을 읽을 수 있으므로 이니셜 라이저의 속성이나 필드에 대한 할당 만 수행하면됩니다. 객체를 생성하고 초기화 한 후에는 FocusManager.SetIsFocusScope(DataGrid_Obj,true)과 같은 명령을 호출해야합니다.

DataGrid_Obj은 생성자가 완료되기 전에 만들어 졌기 때문에 자체 이니셜 라이저에 전혀 사용할 수 없습니다. 그러면 null이됩니다.

그냥

DataGrid DataGrid_Obj = new DataGrid(); 
FocusManager.SetIsFocusScope(DataGrid_Obj,true); 

그래서 내가이 일을해야한다고 생각 물품. (나는 그것을 시도하지 않았다.)

관련 문제