【发布时间】:2020-10-08 08:32:24
【问题描述】:
我有一个绑定,我不需要路径。如果我在 xaml 中设置 ItemTemplate 效果很好。
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="TestBindingPath.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ListView x:Name="listview1" ItemsSource="{Binding Students}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
但是如果我在代码中设置 ItemTemplate 会引发异常
listview1.ItemTemplate = new DataTemplate(() => {
Label label = new Label();
label.SetBinding(Label.TextProperty, new Binding());
return (new ViewCell() {
View = label
});
});
那么如何在代码中为 Binding 设置一个空路径呢?
【问题讨论】:
-
new Binding("");或new Binding("."); -
这个问题解决了吗?如果是这样,请发布您的答案。它将帮助其他有类似主题的人,谢谢。还有一篇关于绑定的有用文章。docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/…
-
您好,new Binding("") 不起作用,但 new Binding(".") 有效。