[英]How access to selected items of a ListView from another class? in WPF C#
I have two views of WPF (Vista1.xaml and Vista2.xaml), and they are part of a MainWindow.xaml. 我有WPF的两个视图(Vista1.xaml和Vista2.xaml),它们是MainWindow.xaml的一部分。 In the Vista1.xaml i have a listview, where the user selects some items by clicking and the Vista2.xaml has a button.
在Vista1.xaml中,我有一个列表视图,用户在其中单击可以选择某些项目,而Vista2.xaml则有一个按钮。 I want that when the user clicks on the button of Vista2.xaml, get the items that the user previously selected in the listview of Vista1.xaml.
我希望当用户单击Vista2.xaml的按钮时,获得用户先前在Vista1.xaml的列表视图中选择的项目。
I have class in the Vista1.xaml.cs ListViewItem_PreviewMouseLeftButtonDown method that captures the user selects the item in the listview. 我在Vista1.xaml.cs的ListViewItem_PreviewMouseLeftButtonDown方法中具有类,该方法捕获用户在列表视图中选择项目。 the code is as follows
代码如下
private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var item = sender as ListViewItem;
if (item != null && item.IsSelected)
{
...
}
}
I appreciate your help 我感谢您的帮助
Add a public property to you MainPage
that contains the data you want to pass between Vista1
and Vista2
. 向您的
MainPage
添加一个公共属性,其中包含要在Vista1
和Vista2
之间传递的数据。 Then, in your event handler of Vista1, set the property and on the button click of Vista2 read the property. 然后,在Vista1的事件处理程序中,设置属性,然后在按钮上单击Vista2以读取该属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.