c# - How to identify the ValidationError ToolTip Placement in WPF TextBox -
i have added arrow indicate textbox tooltip. works great when textbox far away screen edge. when near screen edge. tooltip placement changes , arrow shown on left.
here image correct expected, since textbox in away edges.
but when textbox near edges. see this
i want see arrow in second image on right side of tooltip.
here code
<grid grid.column="0" width="10" margin="1,0,-1,0" background="transparent"> <path height="15" stretch="fill" fill="{dynamicresource controlsvalidationbrush}" data="f1 m 287.328,237.333l 319.344,255.818l 319.344,218.849l 287.328,237.333 z " /> </grid> <border grid.column="1" background="{dynamicresource controlsvalidationbrush}" cornerradius="0"> <textblock maxwidth="250" margin="8,7,8,7" foreground="{dynamicresource whitebrush}" text="{binding (validation.errors)[0].errorcontent}" textwrapping="wrap" uselayoutrounding="false" /> </border>
i created controltemplate
tooltip , show/hide right or left arrow depending on placement of tooltip. here xaml it:
<controltemplate x:key="tooltiptemplate" targettype="{x:type tooltip}"> <stackpanel orientation="horizontal"> <grid x:name="leftgrid" width="10" margin="1,0,-1,0" background="transparent"> <path height="15" stretch="fill" fill="red" data="f1 m 287.328,237.333l 319.344,255.818l 319.344,218.849l 287.328,237.333 z " /> </grid> <border background="red" cornerradius="0"> <textblock maxwidth="250" margin="8,7,8,7" foreground="{dynamicresource whitebrush}" text="this tooltip" textwrapping="wrap" uselayoutrounding="false" /> </border> <grid x:name="rightgrid" width="10" margin="1,0,-1,0" background="transparent"> <path height="15" stretch="fill" fill="red" data="f1 m 287.328,237.333l 319.344,255.818l 319.344,218.849l 287.328,237.333 z " /> </grid> </stackpanel> <controltemplate.triggers> <trigger property="placement" value="left"> <setter targetname="leftgrid" property="visibility" value="hidden"/> <setter targetname="rightgrid" property="visibility" value="visible"/> </trigger> <trigger property="placement" value="right"> <setter targetname="leftgrid" property="visibility" value="visible"/> <setter targetname="rightgrid" property="visibility" value="hidden"/> </trigger> </controltemplate.triggers> </controltemplate> <tooltip x:key="mytooltip" template="{staticresource tooltiptemplate}">
thanks
Comments
Post a Comment