Up vote 0 down vote favorite share g+ share fb share tw.
I don’t know how solve this. I have listbox with context menu. I select listbox item on right click and then choose (click) one item of listbox context menu.
Than I want send selected listbox item to view-model. Problem is , the selected listbox item in view-model is still null. My view look like this: In code behing view I have this on right click on listbox item.
#region listbox events private void ListBox_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { SelectItemOnRightClick(e); e. Handled = true; } private void ListBox_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) { SelectItemOnRightClick(e); FriendContextMenu. PlacementTarget = sender as UIElement; FriendContextMenu.
IsOpen = true; } private void ListBox_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { SelectItemOnRightClick(e); } private void SelectItemOnRightClick(MouseButtonEventArgs e) { Point clickPoint = e. GetPosition(Friends); object element = Friends. InputHitTest(clickPoint); if (element!
= null) { var clickedListBoxItem = GetVisualParent(element); if (clickedListBoxItem! = null) { Friends. SelectedItem = clickedListBoxItem.
Content; ////TEST //var tuple = (KeyValuePair)Friends. SelectedItem; //MessageBox. Show(tuple.Value.
SefNick); } } } public T GetVisualParent(object childObject) where T : Visual { var child = childObject as DependencyObject; while ((child! = null) &&!(child is T)) { child = VisualTreeHelper. GetParent(child); } return child as T; } #endregion Selection with right mouse button works good.
But I have problem send selected item to view-model. Also on double mouse clicked event I haven’t any problem send listbox selected item do view-model. View-model.
Public void Send(KeyValuePair friend) { MessageBox. Show(string. Format("Send for:{0}",friend.Value.
SefNick)); } What I do wrong? Thank. Wpf listbox item link|improve this question asked Dec 15 '10 at 15:24user481758.
You had better bind a SelectedItem property of the ListBox to a proper property in the viewmodel. After that you can use Send without parameters. – vorrtex Dec 15 '10 at 17:14 Ok, I impelent your advance – user481758 Dec 16 '10 at 13:00.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.