How to access ItemsSource property of a DataGrid defined in UserControl from main xaml file?

只谈情不闲聊 提交于 2020-01-17 00:37:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!