c# - TreeViewItem to notify ViewModel when it is hovered -
i using code this blogpost in order have treeview highlight items, hovered mouse. working intended, want treeviewitems notify attached viewmodels when hovered / not hovered.
however i'm @ loss on how can achieve this. corresponding xaml code looks following:
<style targettype="{x:type treeviewitem}"> <style.triggers> <trigger property="controls:treeviewhelper.ismousedirectlyoveritem" value="true"> <setter property="background" value="green" /> </trigger> </stile.triggers> </style>
how can bind property viewmodel, named treenodemodel.ishovered treeviewitem (or attached dependency property ismousedirectlyoveritem) can react on changes within code?
all examples found via google explained how set background color. in advance time on trivial answer.
in style
, try adding setter
binds ismousedirectlyoveritem
ishovered
, , use onewaytosource
binding mode push value right way:
<style targettype="{x:type treeviewitem}"> <setter property="controls:treeviewhelper.ismousedirectlyoveritem" value="{binding path=ishovered, mode=onewaytosource}" /> <style.triggers> ... </style>
edit: ismousedirectlyover
read-only, , read-only dps can't target of bindings, fredrik hedblad's pushbinding
may possible workaround: onewaytosource binding readonly dependency property
<style targettype="{x:type treeviewitem}"> <setter property="pb:pushbindingmanager.stylepushbindings"> <setter.value> <pb:pushbindingcollection> <pb:pushbinding targetdependencyproperty="controls:treeviewhelper.ismousedirectlyoveritem" path="ishovered" /> </pb:pushbindingcollection> </setter.value> </setter> <style.triggers> ... </style>
Comments
Post a Comment