c# - WPF ItemsControl Datattemplate dynamic update -
i'm new in wpf technology , ask possibility of solving of problem.
i have itemscontrol add images:
<itemscontrol name="itemscontrol1" itemssource="{binding path=pictureslist}" itemtemplate="{staticresource picturetemplate}" grid.column="1" /> and have prepare datatemplate:
<datatemplate x:key="picturetemplate"> <datatemplate.resources> <style targettype="image"> <setter property="width" value="180" /> <setter property="height" value="120" /> <setter property="margin" value="10" /> </style> </datatemplate.resources> <image source="{binding path=location}" /> </datatemplate> my problem don't know how can dynamically change parametrs of image width , height. example, when change size of window, need change size of images inside item control.
could me?
thank advice , tips. smith
if controlling size of image based on rest of ui, i.e. window size should avoid setting them explicit values , opt layout panel takes care of you. such making controls items panel wrappanel layout.
<itemspaneltemplate x:key="griditemtemplate"> <wrappanel verticalalignment="center" horizontalalignment="center"/> </itemspaneltemplate> if there in view model dictates size, use binding.
to want specifically, need uniform grid , able bind number of columns collection count. unfortunately can't done knowledge.
as such, i'd create custom layout panel. lots of tutorials available online, create class extends panel , override measureoverride , arrangeoverride methods. important 1 being measure...
protected override size arrangeoverride(size finalsize) { int = 0; foreach( uielement child in internalchildern) { var r = new rect(this.actualsize / this.internalchildren.count * i, 0, this.actualsize / this.interalchildren.count, finalsize.height); child.arrange( r ); i++; } } this approximate code written on phone apologies if needs refactoring.
then use panel itemspanel template shown before.
Comments
Post a Comment