问题
I have declared a DataGrid in UserControl.
Now I have included the UserControl in my main xaml file. I am trying to set the ItemsSource property of DataGrid from main.xaml; but I am getting an error "The property ItemsSource doesnot exist in the namespace".
I am able to set the other properties like Background,Foreground, etc.
My UserControl has this :
<wpfkit:DataGrid Name="DataGrid1"
AutoGenerateColumns="True"
Width="Auto">
</wpfkit:DataGrid>
In main.xaml :
<usercontrol:MultiStepProcessGrid ItemsSource="{Binding GridData}" ></usercontrol:MultiStepProcessGrid>
The above line is giving an error stating that ItemsSource doesnot exist in namespace.
So I wanted to know whether its possible to set the ItemsSource from main.xaml or not!!
Please help me regarding this !!!
回答1:
Try this
<wpfkit:DataGrid Name="DataGrid1"
ItemSource="{Binding}"
AutoGenerateColumns="True"
Width="Auto">
</wpfkit:DataGrid>
and
<usercontrol:MultiStepProcessGrid DataContext="{Binding GridData}" ></usercontrol:MultiStepProcessGrid>
来源:https://stackoverflow.com/questions/3904510/how-to-access-itemssource-property-of-a-datagrid-defined-in-usercontrol-from-mai