Edit: after look at it again, this might actually be an example of the problem described here.
Up vote 0 down vote favorite share g+ share fb share tw.
I'm using a ListView to display contents of a log in my application. I want to change the icon and visibility of a context MenuItem based upon the user's currently selected entry in the ListView. Here is how I'm populating the ListView: // Create the collection view source.
M_CollectionViewSource = new CollectionViewSource(); m_CollectionViewSource. SortDescriptions. Add(new System.ComponentModel.
SortDescription("Time", System.ComponentModel. ListSortDirection. Descending)); m_CollectionViewSource.
Filter += new FilterEventHandler(LogEventCollectionViewSource_Filter); // Create the binding. Binding binding = new Binding(); binding. Source = m_CollectionViewSource; this.
LogEventListView. SetBinding(ListView. ItemsSourceProperty, binding); m_CollectionViewSource.
Source = LogEventManager.Instance. LogEventCollection; And here is where I'm creating my ListView control. Everything works fine except for the binding of the first menu item.
When an item is not selected, I want the first menu item's Visibility to be Collapsed. I also want the context MenuItem image to match that of the selected log event. I have verified that BOTH of my IValueConverter classes are working properly.
For some reason the first MenuItem is always visible and never has an icon. Can someone tell me what I'm overlooking? UPDATE: There seem to be some real issues with binding to the Icon property of a MenuItem in .
NET 3.5 as seen here and here. Problems are compounded by the fact that I'm using an IValueConverter to select the appropriate image. Although it's not the solution I prefer, for now I've just decided to set the values in code-behind in the ContextMenu's opening event.
ContextMenu menu = sender as ContextMenu; if (menu! = null) { MenuItem item = LogicalTreeHelper. FindLogicalNode(menu, "ContextMenuViewDetails") as MenuItem; if (item!
= null) { if (this. LogEventListView.SelectedItems. Count Visibility = Visibility.
Collapsed; else item. Visibility = Visibility. Visible; } } } c# wpf xaml data-binding link|improve this question edited Aug 8 '11 at 16:42 asked Aug 5 '11 at 21:09bporter704110 86% accept rate.
Please post your converter. And you have verified the converter is called? – Blam Aug 5 '11 at 21:48 I've verified that the converters are working.
I've used them in other locations. For some reason they are not being called from this control. – bporter Aug 6 '11 at 0:27.
Edit: after look at it again, this might actually be an example of the problem described here Original answer below, but probably won't work Without seeing the converter I can't comment on why it might not be working, but you could try to achieve the same with a style instead.
Thanks for the suggestion. Unfortunately I wasn't able to get the styles to work either. There seem to be real issues with binding MenuItem properties, particularly the Icon property.
– bporter Aug 8 '11 at 16:10.
Category is a property on the items in an ObservableCollection which are bound to the ListView. – bporter Aug 8 '11 at 16:09.
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.