c# - Wpf Prism give style to each items of a ItemControl (Views in a Region) -
i have wpf
prism
project , has region
base on itemcontrol
:
<itemscontrol prism:regionmanager.regionname="workspaceregion" >
in itemcontrol
see of views
verticaly want give style each item
of itemcontrol
(each view
).
all of items (views) must have same style (for example: background color, padding, margin, border and...)
i want (for example):
i used simple style , code this:
<itemscontrol prism:regionmanager.regionname="workspaceregion" background="#765e4d" margin="10"> <itemscontrol.itemspanel> <itemspaneltemplate> <stackpanel/> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemcontainerstyle> <style> <setter property="control.template"> <setter.value> <controltemplate> <border borderbrush="red" padding="10" borderthickness="1" cornerradius="5"> <contentpresenter content="{binding}"/> </border> </controltemplate> </setter.value> </setter> </style> </itemscontrol.itemcontainerstyle> </itemscontrol>
its error:
a style intended type 'itemscontrol' cannot applied type 'view1'
also tested codes:
<itemscontrol prism:regionmanager.regionname="workspaceregion" background="#765e4d" margin="10"> <itemscontrol.itemspanel> <itemspaneltemplate> <stackpanel/> </itemspaneltemplate> </itemscontrol.itemspanel> <itemscontrol.itemtemplate> <datatemplate> <grid > <textblock text="test"/> <border borderbrush="red" padding="10" margin="10" borderthickness="1" cornerradius="5"> <contentpresenter content="{binding}"/> </border> </grid> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>
but result when write:
<itemscontrol prism:regionmanager.regionname="workspaceregion" >
why? mistake?
how can this?
edit1:
i used <itemspresenter/>
instead of <contentpresenter content="{binding}"/>
result: without change
edit2:
i write style itemcontainerstyle property of itemscontrol , works if remove controltemplate
part it.
now question kind of presenter
or xaml tag
should use inside following controltemplate
views
(usercontrols
) shown.
<style targettype="{x:type usercontrol}" x:key="myitemcontainerstyle"> <setter property="background" value="brown"/> <setter property="borderbrush" value="blue"/> <setter property="borderthickness" value="2"/> <setter property="margin" value="10"/> <setter property="template" > <setter.value> <controltemplate> ?????????????????????????? <!-- following contentpresenter not working , items dose not show --> <contentpresenter/> </controltemplate> </setter.value> </setter> </style>
set contenttemplate
property of style, not control.template
or template
an itemscontrol gets rendered :
<itemscontrol> <itemspanel> <contentpresenter> <itemtemplate> </contentpresenter> <contentpresenter> <itemtemplate> </contentpresenter> <contentpresenter> <itemtemplate> </contentpresenter> </itemspanel> </itemscontrol>
the itemcontainerstyle
applies contentpresenter
object wraps each item in xaml tree, , don't believe contentpresenter
has either control.template
or template
property.
when changing how contentpresenter
displayed should overwrite contenttemplate
property instead.
Comments
Post a Comment