问题
I am trying to do something that should be simple, but think I am just not seeing the answer.
I have a List with several strings.
I would like to bind it to a DevExpress DXGrid.
It appears that the grid is showing the correct number of row, but not displaying my text.
I am using the MVVm patern and have seperated my ViewModel and View.
Thanks for the help.
Here is the XAML code:
<dxg:GridControl Grid.Row="0" DataSource="{Binding Path=ErrorLog}" >
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Error Log" AllowEditing="False" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView NewItemRowPosition="None" />
</dxg:GridControl.View>
</dxg:GridControl>
Here is the View Model Code:
private List<string> _errorLog;
public List<string> ErrorLog
{
get { return _errorLog; }
set
{
_errorLog = value;
OnPropertyChanged("ErrorLog");
}
}
回答1:
You didn't specify what the column should display, so it's not displaying anything...
<dxg:GridColumn Header="Error Log" AllowEditing="False" DisplayMemberBinding="{Binding}" />
(note that there is not path for the binding: the column is bound to the string itself, not a member of the string)
回答2:
that doesn't work.. use this instead
<dxg:GridColumn Header="Value">
<dxg:GridColumn.DisplayMemberBinding>
<Binding Path="RowData.Row"/>
</dxg:GridColumn.DisplayMemberBinding>
</dxg:GridColumn>
回答3:
GridColumn.DisplayMemberBinding is now marked as obsolete. It is suggested that the Binding property should be used instead.
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Value" Binding="{Binding RowData.Row}">
<dxg:GridControl.Columns>
ColumnBase.DisplayMemberBinding Property
来源:https://stackoverflow.com/questions/4004462/devexpress-wpf-grid-bound-to-liststring-using-mvvm