【发布时间】:2016-07-02 05:23:07
【问题描述】:
我有 Comments 课程,我正在绑定:
<ListBox ItemsSource="{Binding CommentFiles}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Text}" TextWrapping="Wrap"/>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding UserId}"/> <!-- Here should be username -->
<TextBlock Text=","/>
<TextBlock Text="{Binding CreatedAt}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
如您所见,Comments 类具有 UserId 属性,这只是一些字符组合。我可以使用异步getUser(userID) 方法获取User 类对象。
当我绑定到 cmets 时,我想查看用户的用户名(在 User 类中)而不是 UserId。
而且我无法编辑课程。有没有办法做到这一点?
【问题讨论】:
-
为什么不能只绑定到 UserName 而不是 UserId?
-
@Breeze 因为
Comments类没有 UserName 属性,我无法更改类。 -
cmets 类是否对用户有任何引用?如何将评论链接到用户?
-
如何使用转换器并通过反射返回用户名?
-
对不起,我没有看到有不同的类。但是如何在 Comments 中创建一个返回用户用户名值的属性呢?
标签: c# wpf binding windows-8.1