【发布时间】:2010-12-09 21:06:24
【问题描述】:
我有这个对象:
class a
{
public string Application;
public DateTime From, To;
}
我用它声明这个列表:
ObservableCollection<a> ApplicationsCollection =
new ObservableCollection<a>();
在我的 XAML 中,我有:
<ListView Height="226.381" Name="lstStatus" Width="248.383" HorizontalAlignment="Left" Margin="12,0,0,12" VerticalAlignment=">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Application"
DisplayMemberBinding="{Binding Path=Application}"/>
<GridViewColumn Width="50" Header="From"
DisplayMemberBinding="{Binding Path=From}"/>
<GridViewColumn Width="50" Header="To"
DisplayMemberBinding="{Binding Path=To}"/>
</GridView>
</ListView.View>
</ListView>
当我这样做时:
lstStatus.ItemsSource = ApplicationsCollection;
我收到一堆错误,但列表视图中没有显示任何内容:
System.Windows.Data Error: 39 : BindingExpression path error: 'Application' property not found on 'object' ''a' (HashCode=60325168)'. BindingExpression:Path=Application; DataItem='a' (HashCode=60325168); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 39 : BindingExpression path error: 'From' property not found on 'object' ''a' (HashCode=60325168)'. BindingExpression:Path=From; DataItem='a' (HashCode=60325168); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 39 : BindingExpression path error: 'To' property not found on 'object' ''a' (HashCode=60325168)'. BindingExpression:Path=To; DataItem='a' (HashCode=60325168); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
很明显,该对象具有a 类型,而a 显然具有正确的属性,那么为什么这不起作用?
【问题讨论】: