저는 WPF 프로젝트에서 작업 중이며 일부 사용자 컨트롤을 만들어야합니다. 지금은 DataGrid를 탐색 할 수있는 탐색 바를 개발 중이므로 XAML 파일에서 탐색 막대에 DataGrid 객체를 전달해야하지만 작동하지 않습니다.WPF에서 컨트롤에 컨트롤을 전달하는 방법?
내 네비게이션 바는 다음
<my:NavigationBar Data="{Binding ElementName=dataGrid1}" HorizontalAlignment="Left" Margin="6,6,0,0" Name="navigationBar1" VerticalAlignment="Top" />
그리고 내 데이터 그리드는 다음과 같습니다 :
<DataGrid AutoGenerateColumns="True" Margin="11,46,12,9" Name="dataGrid1" />
그리고 내 탐색 모음 뒤에 내 코드는 다음과 같습니다 :
public static readonly DependencyProperty dataProperty =
DependencyProperty.Register("Data",
typeof(DataGrid), typeof(NavigationBar));
private DataGrid dataGrid;
public DataGrid Data
{
get
{ return dataGrid; }
set
{ dataGrid = value; }
}
보시다시피,이 작업을 수행하여 탐색 모음에 컨트롤을 보내려고합니다 :
Data="{Binding ElementName=dataGrid1}"
그러나 내 코드에서 dataGrid 변수를 사용하려고하면 dataGrid 변수가 null을 가리키기 때문에 예외가 발생합니다.
그래서 컨트롤을 잘못 전달하고 있습니까? 내가 도대체 뭘 잘못하고있는 겁니까? 내 접근 방식이 가장 적절합니까?
미리 감사드립니다.
작동합니다! 고맙습니다! 더 나은 접근 방법을 찾고자합니다. – Dante