c# - hittesting on Listitems in a Listbox -
i customized listbox show pie-chart (each listitem 1 slice of pie). used itemtemplate (for now) consists of shape
. make shapes form full circle, calculated start/endangle each piece , used custom itemspaneltemplate
stack items on top of each other.
when click anywhere near pie, "last" item gets selected since located on top of others. quite obvious, hoped since itemtemplate contains shape
, inherit hit-testing there , not assume items represented rectangles.
where supposed include hittesting? set ishittestvisible="false"
inside itemtemplate
, except shape - since doesn't contain except shape, stuck right now.
edit:
i tried surrounding shape
grid transparent background, on did set ishittestvisible="false"
. still results in selecting last element on each click while would've assumed nothing selected. think might confused how hittesting supposed work?
code:
since new wpf might have missed during implementation. added relevant codeparts of minimal example:
my shape
-class:
public class piepiece : shape { protected override geometry defininggeometry { { return getpiegeometry() } } //some dependencyproperties , helper methods. private geometry getpiegeometry() { //calculations } }
xaml:
<window [...] xmlns:runner="clr-namespace:mynamespace"> <window.resources> <!-- custom converters --> <!-- listbox-style custom controltemplate listbox --> <itemspaneltemplate x:key="itempanel"> <grid/> </itemspaneltemplate> </window.resources> <listbox [...] itemspanel="{staticresource itempanel}"> <listbox.itemtemplate> <datatemplate> <grid background="{x:null}" ishittestvisible="false"> <runner:piepiece ishittestvisible="false" [...]> <!-- dependency properties set via multibinding here --> </runner:piepiece> </grid> </datatemplate> </listbox.itemtemplate> </listbox> </window>
i found reason why hittesting did not work desired:
the default template listboxitem-style surrounds contentpresenter
border
transparent background. click-events caught , handled border, instead of contentpresenter
. writing own style listboxitem , setting background {x:null}
suggested gaz fixed problem (as did removing border, added 1 further customizations).
Comments
Post a Comment