c# - Remove Separators focus from ListViewItem -
i wrote listviewitem style contains separator in contenttemplate. problem when click item, separator have focus contentpresenter. want remove separators focus , contentpresenter have focus.
what should do?
<style x:key="altitembackground" targettype="{x:type listviewitem}"> <setter property="template"> <setter.value> <controltemplate> <stackpanel> <separator x:name="separator"/> <contentpresenter content="{binding}" /> </stackpanel> </controltemplate> </setter.value> </setter> <style.triggers> <trigger property="itemscontrol.alternationindex" value="0"> <setter property="background" value="white"></setter> </trigger> <trigger property="itemscontrol.alternationindex" value="1"> <setter property="background" value="#e6e6e6"></setter> </trigger> </style.triggers> </style>
using default controltemplate
of listviewitem
, modifying bit created application, maybe you're looking for:
<window x:class="listviewitemseparator.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:system="clr-namespace:system;assembly=mscorlib" mc:ignorable="d" title="mainwindow" height="350" width="525"> <window.resources> <style targettype="{x:type listviewitem}"> <setter property="template"> <setter.value> <controltemplate targettype="listboxitem"> <stackpanel> <separator x:name="separator" /> <border borderthickness="{templatebinding border.borderthickness}" padding="{templatebinding control.padding}" borderbrush="{templatebinding border.borderbrush}" background="{templatebinding panel.background}" name="bd" snapstodevicepixels="true"> <contentpresenter content="{templatebinding contentcontrol.content}" contenttemplate="{templatebinding contentcontrol.contenttemplate}" contentstringformat="{templatebinding contentcontrol.contentstringformat}" horizontalalignment="{templatebinding control.horizontalcontentalignment}" verticalalignment="{templatebinding control.verticalcontentalignment}" snapstodevicepixels="{templatebinding uielement.snapstodevicepixels}" /> </border> </stackpanel> <controltemplate.triggers> <multitrigger> <multitrigger.conditions> <condition property="uielement.ismouseover" value="true" /> </multitrigger.conditions> <setter property="panel.background" targetname="bd" value="#1f26a0da" /> <setter property="border.borderbrush" targetname="bd" value="#a826a0da" /> </multitrigger> <multitrigger> <multitrigger.conditions> <condition property="selector.isselectionactive" value="false" /> <condition property="selector.isselected" value="true" /> </multitrigger.conditions> <setter property="panel.background" targetname="bd" value="#3ddadada" /> <setter property="border.borderbrush" targetname="bd" value="#ffdadada" /> </multitrigger> <multitrigger> <multitrigger.conditions> <condition property="selector.isselectionactive" value="true" /> <condition property="selector.isselected" value="true" /> </multitrigger.conditions> <setter property="panel.background" targetname="bd" value="#3d26a0da" /> <setter property="border.borderbrush" targetname="bd" value="#ff26a0da" /> </multitrigger> <trigger property="uielement.isenabled" value="false"> <setter property="textelement.foreground" targetname="bd" value="{dynamicresource {x:static systemcolors.graytextbrushkey}}" /> </trigger> <datatrigger binding="{binding relativesource={relativesource previousdata}}" value="{x:null}"> <setter targetname="separator" property="visibility" value="collapsed"></setter> </datatrigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> <setter property="focusvisualstyle" value="{x:null}" /> <style.triggers> <trigger property="itemscontrol.alternationindex" value="0"> <setter property="background" value="white"></setter> </trigger> <trigger property="itemscontrol.alternationindex" value="1"> <setter property="background" value="#e6e6e6"></setter> </trigger> </style.triggers> </style> </window.resources> <grid> <listview itemscontrol.alternationcount="2"> <system:string>first item</system:string> <system:string>second item</system:string> <system:string>third item</system:string> <system:string>fourth item</system:string> <system:string>fifth item</system:string> </listview> </grid> </window>
unselected state:
selected state:
Comments
Post a Comment