【发布时间】:2017-05-22 23:35:29
【问题描述】:
如何在已将 x:DataType 设置为类的绑定中调用自定义方法?错误消息显示:在类型“Family”中找不到属性“TotalMembers”。将页面加载中的方法添加到 Family 类时,错误仍然存在。
// model
public class Family
{
public int ID { get; set; }
public string Surname { get; set; }
public int TotalMembers() { return "some code..." }
}
public class Person
{
public int ID { get; set; }
public int FamilyID { get; set; }
public string FirstName { get; set; }
}
// page load
public ObservableCollection<Family> ocFamily { get; set; }
ocFamily = new ObservableCollection<Family>();
// xaml
<ListView ItemsSource="{x:Bind ocFamily}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="data:Family>
<StackPanel>
<TextBlock Text="{x:Bind Surname}" />
<TextBlock Text="{x:Bind TotalMembers()}" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
第二个文本块应该显示家庭成员的总数。
【问题讨论】:
-
我应该使用转换器吗?
-
您使用的是什么版本的 Windows 10?
-
最低版本:Windows 10.0; Build 10586,目标版本:Windows 10 周年纪念版 10.0; 14393
标签: xaml uwp win-universal-app windows-10-universal uwp-xaml