سؤال

I'm still new to WPF, and I'm trying to do something that's beyond my knowledge at the moment.

I have a listbox databinded to the source collection, and a label. I'd like to bind the label's Content value to the listbox's item over which is mouse hovered.

Say I have DataTemplate binded to the class MenuItem:

<DataTemplate DataType="{x:Type local:MenuItem}" x:Key="MenuListTemplate">

Which has member Text. I want my Label to display Text from element which is mouse overed in list. I have the IsMouseOver trigger for my textbox, but have no idea how to bind Label.Content to it.

Any tips?

هل كانت مفيدة؟

المحلول

I don't think that binding can achieve your goal with ease. I think it's easier to do with routed events.

Subscribe to the MouseMove event at the ListBox level. Check if the source of the event is a ListBoxItem, and if it is use this item to update the label.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top