我有一个接口:
public interface IDocument : IEntity
{
string FileName { get; set; }
...
}
public interface IEntity : IComparable
{
int Id { get; set; }
...
}
我想绑定如下:
<ItemsControl Grid.Row="0" ItemsSource="{Binding SelectedEventPhotoList}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Name="SelectedListView">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="1" Columns="3"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=(documents:IDocument.FileName)}"/>
<TextBlock Text="{Binding Path=(documents:IDocument.Id)}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
使用SelectedEventPhotoList查看模型如下:
public List<IDocument> SelectedEventPhotoList
{
get { return _selectedEventPhotoList; }
set
{
if (Equals(value, _selectedEventPhotoList))
return;
_selectedEventPhotoList = value;
RaisePropertyChanged(() => SelectedEventPhotoList);
}
}
第一次绑定到FileName工作正常,但第二次没有。
如何让它发挥作用?
答案 0 :(得分:1)
如果IEntity.Id
是明确实现的属性,则应在绑定路径中将IDocument
替换为IEntity
:
<TextBlock Text="{Binding Path=(documents:IEntity.Id)}"/>
如果不是,您应该能够使用通用绑定语法绑定它:
<TextBlock Text="{Binding Path=Id}"/>