我正在使用Xamarin.Forms并尝试使用MVVM体系结构。
我有一个ContentPage,上面有一个简单的列表视图。列表视图具有绑定到我的ViewModel的项源属性。我可以很好地填充列表。所有项目均按应有的方式显示。
当我单击列表中的项目时,我需要根据所选项目导航到其他页面。这是行不通的。仅当我直接引用我的基础模型(这不是我想做的)时,它才有效
我有ListView.ItemSelected事件编码。但是,Item Selected事件无法确定所选List Item的“ display_text”是什么。如何实现此目的而不必直接从我的视图(页面)中引用我的模型?
主页代码:
public partial class MainPage : ContentPage
{
private int intPreJobFormID = 0;
public MainPage()
{
InitializeComponent();
BindingContext = new MainPageViewModel();
Label lblHeader = new Label
{
Text = "HW Job Assessments",
FontSize = ViewGlobals.lblHeader_FontSize,
HorizontalOptions = ViewGlobals.lblHeader_HorizontalOptions,
FontAttributes = ViewGlobals.lblHeader_FontAttributes,
TextColor = ViewGlobals.lblHeader_TextColor
};
//Create the Main Menu Items List View
var lvMain = new ListView
{
//Pull down to refresh list
IsPullToRefreshEnabled = true,
//Define template for displaying each item.
//Argument …Run Code Online (Sandbox Code Playgroud)