C#跨页面共享listview项目
我是初学者 我在主页上有一个列表,通过在文本框中键入内容来添加项目。创建listview项目后,我希望能够单击项目并在另一个页面中查看其值 我为此创建了一个DetailsPage,但我不知道在这些页面上共享数据的最佳方式是什么 这是我目前在主页上看到的内容: 公共密封部分类主页面:第页 { 公共项目计数器C#跨页面共享listview项目,c#,list,class,model-view-controller,uwp,C#,List,Class,Model View Controller,Uwp,我是初学者 我在主页上有一个列表,通过在文本框中键入内容来添加项目。创建listview项目后,我希望能够单击项目并在另一个页面中查看其值 我为此创建了一个DetailsPage,但我不知道在这些页面上共享数据的最佳方式是什么 这是我目前在主页上看到的内容: 公共密封部分类主页面:第页 { 公共项目计数器 public MainPage() { this.InitializeComponent(); //This is the button that
public MainPage()
{
this.InitializeComponent();
//This is the button that submits the entered text
public void btnSubmitInPopup_Click_1(object sender, RoutedEventArgs e)
{
//Create new listview item and textblock
ListViewItem item = new ListViewItem();
TextBlock txtBloodSugarValue = new TextBlock();
//Save text input value to label and add item to list
txtBloodSugarValue.Text = txtInput.Text;
item.Content = txtBloodSugarValue;
mainListView.Items.Add(item);
//Reset text input field
txtInput.Text = "";
//Update counter of items in list
itemCounter = mainListView.Items.Count();
lblItemCounter.Text = itemCounter.ToString();
}
}
我的DetailPage实际上只有一个标签,我正试图用我在主页中单击的listview项目中的任何值填充该标签
最好的方法是什么?
希望这是有意义的
非常感谢。您有三种方法:
public static int StaticVariable { get; set; }//First Method
public int PublicProperty { get; set; }
public Form2(int Value)
{
InitializeComponent();
//Do your code here with constructor way here
}
public Form2()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//Do your code for 1,2 here
}
public void SetValueWithFunction(int value)
{
//Do your code for setting value with second type in Number 3
}
我希望这有帮助:)谢谢你的回复,我用代码回复了你的评论。@Liz4112我在上面添加了完整的代码,希望你能使用它