[英]Specified cast is not valid (xamarin forms)
this exact same code ran just fine an hour ago.这个完全相同的代码在一小时前运行得很好。 tweaked a couple things, then ctrl+Z back to this state every time i run it on the android emulator now, it hangs and crashes when i try to load the all products page.调整了一些东西,然后每次我在 android 模拟器上运行它时 ctrl+Z 回到这个状态,当我尝试加载所有产品页面时它挂起并崩溃。 VS2019 usually helpful, but not in this case: System.InvalidCastException: 'Specified cast is not valid.' VS2019 通常有帮助,但在这种情况下无效: System.InvalidCastException: 'Specified cast is not valid.' - tried to search, wound up here, where i found a few other similarly titled issues, but the cases were way different. - 尝试搜索,在这里结束,在那里我发现了其他一些类似标题的问题,但情况大不相同。 no clue what's going on, no error messages from IDE before running.不知道发生了什么,在运行之前没有来自 IDE 的错误消息。 EDIT #1: breakpoint seems to be at the END of the the code-behind.编辑#1:断点似乎在代码隐藏的末尾。 EDIT #2: tried iOS and same issue, except now when it crashes, the IDE brings up a window: Main.iOS "UIApplication.Main(args, null, "AppDelegate");"编辑 #2:尝试过 iOS 和同样的问题,除了现在崩溃时,IDE 会弹出一个窗口: Main.iOS "UIApplication.Main(args, null, "AppDelegate");" and reads me the same error.并给我读同样的错误。 - again, confused, as it was all working fine. - 再次困惑,因为一切正常。 and i haven't even looked at Main.cs in days, let alone changed it.而且我已经好几天没看 Main.cs 了,更不用说更改它了。
public class Product
{
public string UPC { get; set; }
public string Brand { get; set; }
public int Count { get; set; }
public string Manufacturer { get; set; }
public string Style { get; set; }
public string SellPrice { get; set; }
public double BuyPrice { get; set; }
public string Market { get; set; }
public bool Buying { get; set; }
public string BoxImage { get; set; }
}
<ContentPage.BindingContext>
<model:Product/>
</ContentPage.BindingContext>
<ContentPage.Content>
<StackLayout>
<ListView x:Name="productsListView">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="75"/>
<ColumnDefinition Width="75"/>
<ColumnDefinition Width="75"/>
</Grid.ColumnDefinitions>
<Label Text="{Binding UPC}"
Grid.Column="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding Brand}"
Grid.Column="2" HorizontalTextAlignment="End" VerticalTextAlignment="Center"/>
<Label Text="{Binding Count}"
Grid.Column="3" HorizontalTextAlignment="Start" VerticalTextAlignment="Center"/>
<Label Text="{Binding Market}"
Grid.Column="4" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding BuyPrice}"
Grid.Column="5" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
public partial class AllProductsPage : ContentPage
{
public AllProductsPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
{
using (SQLiteConnection conn = new SQLiteConnection(App.DatabasePath))
{
conn.CreateTable<Product>();
var products = conn.Table<Product>().ToList();
productsListView.ItemsSource = products;
}
}
}
}
i don't know why, but adding <ViewCell></ViewCell>
around the <Grid></Grid>
seems to get it to work on some level.我不知道为什么,但是在<Grid></Grid>
周围添加<ViewCell></ViewCell>
<Grid></Grid>
似乎让它在某种程度上起作用。
at least i can move on now, but i really wish someone could explain.至少我现在可以继续前进,但我真的希望有人能解释一下。 why was it such and issue?为什么会这样? why wasn't it clear (in the IDE or the Documentation)?为什么不清楚(在 IDE 或文档中)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.