【发布时间】:2019-04-02 23:14:57
【问题描述】:
如何在 XAML 中访问我的 ViewModel 的属性?
我只在 ListView 选择了一个项目时才尝试启用按钮。所选项目是绑定到我的 ViewModel 中的 SelectedCar 的数据。现在,我想检查 SelectedCar 是否为空,如果是,则禁用按钮;否则启用它。
我试过这样的
<StackLayout Orientation="Vertical">
<ListView x:Name="lvwCars" ItemsSource="{Binding Cars}"
SelectedItem="{Binding SelectedCar}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding PlateNumber}" />
<Label Text="{Binding OwnerName}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Button x:Name="btnBack"
Text="Back"
Command="{Binding BackClickCommand}"/>
<Button x:Name="btnNext"
Text="Next"
IsEnabled="False"
Command="{Binding ConfirmClickCommand}">
<Button.Triggers>
<DataTrigger TargetType="Button"
Binding="{Binding Source={x:Reference MyCarsViewModel}, Path=SelectedCarProperty}" Value="null">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Button.Triggers>
</Button>
</StackLayout>
【问题讨论】:
-
你试过“{Binding SelectedCar}”吗?
-
它就在提供的代码中?
标签: listview xamarin.forms selecteditem