SilverLight 中ListBox获取选中项

◇◆丶佛笑我妖孽 提交于 2020-02-27 04:18:43
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(); }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!