我有一个ListView,当您单击该项目时,它会打开一个包含许多详细信息的新页面,但是,如果单击“名称”(标题),它将显示一个包含该客户详细信息的弹出窗口。
我的问题是“名称/标题”单击不起作用。
public ICommand CommandShowInfo { get; set; }
public CustomerListViewModel(INavigation navigation, DateTime month)
{
_navigation = navigation;
CommandShowInfo = new Command(ShowCustomerInfo);
....
}
private async void ShowCustomerInfo(object obj)
{
if (obj.ToString() == "SHOW-MAIN")
{
CustInfoSelectedCustomer = MainCustomer;
showDetails = true;
}
else if (obj.ToString() == "SHOW")
{
// TODO get correct customer to populate popup
CustInfoSelectedCustomer = SelectedCustomer;
showDetails = true;
}
else
{
showDetails = false;
}
}
<ListView ItemsSource="{Binding SummaryReports.ResultSet}" SelectedItem="{Binding SelectedCustomer}" HorizontalOptions="Fill">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal" Padding="10,5,0,5" HorizontalOptions="Fill" Spacing="0">
<StackLayout Orientation="Vertical" Padding="10,0,0,0" HorizontalOptions="FillAndExpand" Spacing="0">
<StackLayout Orientation="Horizontal" Padding="0,0,0,5">
<Label
Text="{Binding Customer.Name}"
LineBreakMode="TailTruncation"
Font="{x:Static statics:Fonts.ListItemTitle}"
TextColor="{x:Static statics:Palette.ListItemTitle}" />
<Image Source="info.png" Grid.Row="0" Grid.Column="2" HorizontalOptions="EndAndExpand" VerticalOptions="Center" WidthRequest="60" HeightRequest="20">
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding CommandShowInfo}"
CommandParameter="SHOW" />
</Image.GestureRecognizers>
</Image>
</StackLayout>
</StackLayout>
<StackLayout>
....
答案 0 :(得分:0)
我已经运行了您的代码,没有问题。您可以尝试
ALTER TABLE `stocktakings` MODIFY `stocktakings`.`status` ENUM(
'ready_for_relocation',
'search_shelf_location',
'stock_update_succeeded',
'stock_update_failed',
'updating_stock'
);
在模型中,您应该确保<Label
Text="{Binding Name}"
Style="{DynamicResource TitleStyle}">
<Label.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding CommandShowInfo}"
CommandParameter="Binding ." />
</Label.GestureRecognizers>
</Label>
必须位于 ListView.ItemSource 中,否则将无法正常工作。就像这样
CommandShowInfo
在contentapge中
class Monkey
{
public string Name { set; get; }
public System.Windows.Input.ICommand CommandShowInfo { get; set; }
}
class MonkeysViewModel
{
public MonkeysViewModel()
{
private async void ShowCustomerInfo(object obj)
{
Console.WriteLine("true");
}
Monkeys = new List<Monkey>();
//f = new F[5];
Monkeys.Add(new Monkey
{
Name = "AS",
CommandShowInfo = new Command(ShowCustomerInfo)
});
}
}
在xaml中
BindingContext = new MonkeysViewModel();
因此 <ListView ItemsSource="{Binding Monkeys}"
可以正常工作。