我想将项目绑定ListView到 ViewModel 中的属性而不是 ItemsSource,但在尝试后Binding Source={x:Reference Name=ThisPage} Path=ViewModel.TimerValue它不起作用。我做错了什么。无法识别
我试过设置:
Text="{Binding Path=TimerValue, TargetNullValue='00:00', FallbackValue='00:00', StringFormat='{0:mm\\:ss}', Source={x:Reference Name=ThisPage}}"
ViewModel 确实实现了 INotifyPropertyChanged 并引发了 PropertyChanged 事件
页面标题 - 参考
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="App3.Views.MyPage"
x:Name="ThisPage">
<ListView x:Name="listView" ItemsSource={Binding Items}>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Path=TimerValue, TargetNullValue='00:00', FallbackValue='00:00', StringFormat='{0:mm\\:ss}', Source={x:Reference Name=ThisPage}}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
代码隐藏
private MyViewModel ViewModel;
public MyPage () {
InitializeComponent ();
ViewModel = new MyViewModel ();
this.BindingContext = ViewModel;
}
慕婉清6462132
蝴蝶刀刀
炎炎设计
相关分类