【发布时间】:2017-05-20 05:14:53
【问题描述】:
我有一个对象列表,我绑定到 NavigationPage 上的 ListView
这里是视图:
<ListView HasUnevenRows="true" x:Name="note_list" HorizontalOptions="FillAndExpand" HeightRequest="50" ItemSelected="note_clicked">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Margin="10, 0, 0, 0" HorizontalOptions="FillAndExpand" Orientation="Vertical" VerticalOptions="Fill">
<StackLayout Margin="10 ,10, 10, 0" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<Image IsVisible="{Binding responseRequired, Mode=TwoWay}" Source="icons/blue/warning" WidthRequest="20" HorizontalOptions="Start" Margin="0, 0, 0, 0"></Image>
<Label HorizontalOptions="Start" Margin="0, 0, 0, 0" FontSize="18" VerticalOptions="CenterAndExpand" Text="{Binding userId , Mode=TwoWay}"></Label>
<Label HorizontalTextAlignment="End" VerticalOptions="Center" HorizontalOptions="EndAndExpand" TextColor="#c1c1c1" FontSize="14" Text="{Binding daysFromPost , Mode=TwoWay}"></Label>
</StackLayout>
<StackLayout HorizontalOptions="Fill" Orientation="Vertical" Margin="10, -5, 10, 10">
<StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal" Margin="0, -2, 0, 0">
<Label FontSize="14" TextColor="#c1c1c1" Text="to: "></Label>
<Label HorizontalOptions="StartAndExpand" FontSize="14" TextColor="#c1c1c1" Text="{Binding noteToo, Mode=TwoWay}"></Label>
</StackLayout>
<Label FontSize="14" TextColor="Gray" Text="{Binding note, Mode=TwoWay}"></Label>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
想象一下,当我单击一个日志时,它会转到另一个页面,其中包含日志详细信息以及更改该日志的选项。使用 MVVM 方法将更改绑定到模型视图,我保存更改然后弹出详细信息导航页面。但是当日志列表显示备份时,在页面由于某种原因重新加载之前,这些更改是不可见的。双向绑定不应该导致将更改推送到视图吗?还是我要通过重写 OnAppering() 手动重新加载模型视图?
【问题讨论】:
-
您能分享一下您是如何将 ListView 绑定到集合的吗?此外,显示任何对象的代码是这些单元格的 BindingContext。它将是具有 responseRequired 作为属性的类。
标签: c# mvvm xamarin xamarin.forms