c# - Applying ControlTemplate to a WPF TreeViewItem reduced bitmap icons quality -
i applied hierarchicaldatatemplate
adding icons tree items way:
<treeview.itemtemplate> <hierarchicaldatatemplate datatype="{x:type dataaccess:idataaccessible}" itemssource="{binding path=items}"> <stackpanel orientation="horizontal" margin="2" datacontext="{binding}"> <image width="16" height="16" snapstodevicepixels="true" source="{binding converter={staticresource treeimageconverter}}"> </image> <textblock text="{binding path=name}" margin="5,0" /> </stackpanel> </hierarchicaldatatemplate> </treeview.itemtemplate>
and added itemcontainerstyle
hiding arrow button:
<treeview.itemcontainerstyle> <style targettype="treeviewitem"> <setter property="template"> <setter.value> <controltemplate targettype="treeviewitem" xmlns:s="clr-namespace:system;assembly=mscorlib"> <grid> <grid.columndefinitions> <columndefinition width="auto" minwidth="19" /> <columndefinition width="auto" /> <columndefinition width="*" /> </grid.columndefinitions> <grid.rowdefinitions> <rowdefinition height="auto" /> <rowdefinition /> </grid.rowdefinitions> <!-- make togglebutton invisible --> <togglebutton ischecked="false" visibility="hidden" clickmode="press" name="expander" > </togglebutton> <border borderthickness="{templatebinding border.borderthickness}" padding="{templatebinding control.padding}" borderbrush="{templatebinding border.borderbrush}" background="{templatebinding panel.background}" name="bd" snapstodevicepixels="true" grid.column="1"> <contentpresenter content="{templatebinding headeredcontentcontrol.header}" contenttemplate="{templatebinding headeredcontentcontrol.headertemplate}" contentstringformat="{templatebinding headereditemscontrol.headerstringformat}" contentsource="header" name="part_header" horizontalalignment="{templatebinding control.horizontalcontentalignment}" snapstodevicepixels="{templatebinding uielement.snapstodevicepixels}" /> </border> <itemspresenter name="itemshost" grid.column="1" grid.row="1" grid.columnspan="2" /> </grid> <controltemplate.triggers> <trigger property="itemscontrol.hasitems"> <setter property="uielement.visibility" targetname="expander"> <setter.value> <x:static member="visibility.hidden" /> </setter.value> </setter> <trigger.value> <s:boolean>false</s:boolean> </trigger.value> </trigger> <trigger property="treeviewitem.isselected"> <setter property="panel.background" targetname="bd"> <setter.value> <dynamicresource resourcekey="{x:static systemcolors.highlightbrushkey}" /> </setter.value> </setter> <setter property="textelement.foreground"> <setter.value> <dynamicresource resourcekey="{x:static systemcolors.highlighttextbrushkey}" /> </setter.value> </setter> <trigger.value> <s:boolean>true</s:boolean> </trigger.value> </trigger> <multitrigger> <multitrigger.conditions> <condition property="treeviewitem.isselected"> <condition.value> <s:boolean>true</s:boolean> </condition.value> </condition> <condition property="selector.isselectionactive"> <condition.value> <s:boolean>false</s:boolean> </condition.value> </condition> </multitrigger.conditions> <setter property="panel.background" targetname="bd"> <setter.value> <dynamicresource resourcekey="{x:static systemcolors.controlbrushkey}" /> </setter.value> </setter> <setter property="textelement.foreground"> <setter.value> <dynamicresource resourcekey="{x:static systemcolors.controltextbrushkey}" /> </setter.value> </setter> </multitrigger> <trigger property="uielement.isenabled"> <setter property="textelement.foreground"> <setter.value> <dynamicresource resourcekey="{x:static systemcolors.graytextbrushkey}" /> </setter.value> </setter> <trigger.value> <s:boolean>false</s:boolean> </trigger.value> </trigger> </controltemplate.triggers> </controltemplate> </setter.value> </setter> </style> </treeview.itemcontainerstyle>
and that's how looks before , after:
what can reason quality reduction?
set layoutrounding property true. happens when after layout calculation position cannot directly mapped screen pixel, , color value bleeds 2 display pixels. consider horizontal line placed on y=3, fill line complete color, if placed on y=3.5 need half fill line on 3 , half on 4. there aren't half pixel obviously, thats why blends color between line. half transparent line on y 3 , 4.
sometimes desired animations, because sub pixel rendering makes little bit smoother, icons undesirable.
Comments
Post a Comment