c# - Binding to ActualWidth in changing collection -
i have flipview
control witch consists of image , text image. want text same width image. of images have different dimensions others.
here xaml code:
<flipview x:name="flipview" horizontalcontentalignment="center" verticalcontentalignment="center" itemssource="{binding imageswithdescriptions}"> <flipview.itemtemplate> <datatemplate> <grid x:name="grid" tapped="flipview_tapped"> <grid.rowdefinitions> <rowdefinition height="3*"/> <rowdefinition /> </grid.rowdefinitions> <image x:name="image" grid.rowspan="2" source="{binding image}"></image> <grid x:name="textgrid" grid.row="1"> <grid.background> <solidcolorbrush color="black" opacity="0.5"/> </grid.background> <textblock foreground="white" horizontalalignment="left" fontsize="20" text="{binding description}"/> </grid> </grid> </datatemplate> </flipview.itemtemplate> </flipviewcontrol>
if try bind text image's actualwidth
returns 0. there way that?
edit:
looks this:
(------------------flipview width----------------------) --------------------------------------------------------f | |this image. it's height | |l | |equals flipview's height, | |i | |but width depends on picture's| |p | |ratio, might differ on | |v | |some pictures. | |i | | | |e | | | |w | | | | | | | |h | | | |e |----------|------------------------------|------------|i |this |where grid named "textgrid" is|now (it's |g |width |the same flipview's) | |h --------------------------------------------------------t
but want grid
named "textgrid" have same width image has.
binding <grid x:name="textgrid" width="{binding elementname=image, path=actualwidth}"/>
leads grid
's width being equal 0. image loaded event returns actualwidth
0.
<flipview x:name="flipview" itemssource="{binding listtest}" horizontalcontentalignment="center" verticalcontentalignment="center" > <flipview.itemtemplate> <datatemplate> <grid x:name="grid" background="blue" > <grid.rowdefinitions> <rowdefinition height="3*"/> <rowdefinition /> </grid.rowdefinitions> <grid grid.rowspan="2" x:name="image"> <image stretch="uniform" sizechanged="image_sizechanged" source="{binding url}" ></image> </grid> <grid x:name="textblockgrid" grid.row="1" background="gray"> <textblock foreground="white" textwrapping="wrap" horizontalalignment="left" fontsize="20" text="texxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx trysffffffffffffff sdfffffffffffff dfhdffffffffffffff dfhhhhhhhhx"/> </grid> </grid> </datatemplate> </flipview.itemtemplate> </flipview> private void image_sizechanged(object sender, sizechangedeventargs e) { flipviewitem item = (flipviewitem) flipview.containerfromitem((sender image).datacontext); var text = findelementinvisualtree<textblock>(item); (text.parent grid).width = (sender image).actualwidth; } private t findelementinvisualtree<t>(dependencyobject parentelement) t : dependencyobject { var count = visualtreehelper.getchildrencount(parentelement); if (count == 0) return null; (int = 0; < count; i++) { var child = visualtreehelper.getchild(parentelement, i); if (child != null && child t) return (t)child; else { var result = findelementinvisualtree<t>(child); if (result != null) return result; } } return null; }
Comments
Post a Comment