View Code
private void TongZhiGG_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBoxItem _selectedItem = (ListBoxItem)(TongZhiGG.ItemContainerGenerator.ContainerFromItem(this.TongZhiGG.SelectedItem)); TextBlock myTxt = FindFirstVisualChild<TextBlock>(_selectedItem, "MyOID"); string Select_value = myTxt.Text.ToString(); //MessageBox.Show(Select_value.ToString()); Aggregator.SendMessage<MessageToKranthi, string>( new MessageToKranthi { Payload = "页面跳转"+Select_value} ); } #endregion public T FindFirstVisualChild<T>(DependencyObject obj, string childName) where T : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null && child is T && child.GetValue(NameProperty).ToString() == childName) { return (T)child; } else { T childOfChild = FindFirstVisualChild<T>(child, childName); if (childOfChild != null) { return childOfChild; } } } return null; }
或者 取用WCF
private void TongZhiGG_SelectionChanged(object sender, SelectionChangedEventArgs e) {Info i = (Info)this.TongZhiGG.SelectedItem; string a = i.A_InfoOID.ToString(); }
来源:https://www.cnblogs.com/zgz_dpl/archive/2011/02/16/1956195.html