c# - Show IDataErrorInfo errors in tooltip on keyboard focus and mouse over -


i have textbox shows idataerrorinfo validation information via tooltip using style:

<style x:key="entitypropertytextboxerrorstyle" targettype="{x:type textbox}"          basedon="{staticresource {x:type textbox}}">     <setter property="validation.errortemplate">         <setter.value>             <controltemplate>                 <!-- gets rid of adornment including default red border -->                 <adornedelementplaceholder />             </controltemplate>         </setter.value>     </setter>     <style.triggers>         <trigger property="validation.haserror" value="true">             <setter property="tooltip"                  value="{binding relativesource={relativesource self},                 path=(validation.errors)[0].errorcontent}"/>             <setter property="background" value="mistyrose" />         </trigger>     </style.triggers> </style> 

now want tooltip show on keyboard focus well.

the best solution found use popup instead of tooltip:

<controltemplate x:key="errortemplate">     <stackpanel>         <adornedelementplaceholder x:name="controlwitherror" />         <popup placementtarget="{binding elementname=controlwitherror}" placement="top">             <popup.isopen>                 <multibinding converter="{staticresource atleastonetrueconverter}">                     <binding path="adornedelement.ismouseover"                              elementname="controlwitherror" mode="oneway" />                     <binding path="adornedelement.iskeyboardfocuswithin"                              elementname="controlwitherror" mode="oneway" />                 </multibinding>             </popup.isopen>             <border borderthickness="1">                 <textblock text="{binding                                    adornedelement.(validation.errors)[0].errorcontent,                                   elementname=controlwitherror}"                             background="white"                              fontsize="8" />             </border>         </popup>     </stackpanel> </controltemplate> <style x:key="entitypropertytextboxerrorstyle" targettype="{x:type textbox}"        basedon="{staticresource {x:type textbox}}">     <setter property="validation.errortemplate" value="{staticresource errortemplate}" />     <style.triggers>         <trigger property="validation.haserror" value="true">             <setter property="background" value="mistyrose" />         </trigger>     </style.triggers> </style> 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -