LookUpEdit绑定实体类困扰了我很久,明明和工作室万哥的前台代码是差不多的,但是怎么也绑不成功。后来经过老师的帮忙调试,才找到问题,而这个源头也让我十分吐血,居然是GridControl的Name属性值设的不对,必须要设Name=PART_GridControl,想了半天还是没有想明白。现附上代码
首先是Xaml
<dxg:LookUpEdit Height="25" Name="txtSupplierId" DisplayMember="id" AutoPopulateColumns="False" AutoComplete="True" IncrementalFiltering="True" ImmediatePopup="True" IsPopupAutoWidth="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsTextEditable="False" SelectedIndex="-1" PopupOpening="chooseSupplierId"> <dxg:LookUpEdit.PopupContentTemplate> <ControlTemplate> <dxg:GridControl Name="PART_GridControl" ItemsSource="{Binding}"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="编号" Binding="{Binding id}"/> <dxg:GridColumn FieldName="供应商名称" Binding="{Binding csuppliername}"/> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TableView ShowGroupPanel="False"/> </dxg:GridControl.View> </dxg:GridControl> </ControlTemplate> </dxg:LookUpEdit.PopupContentTemplate> </dxg:LookUpEdit>