c# - Converter not found? XamlParseException: Cannot find a Resource with the Name/Key StringTruncator -


i've included stringtruncator converter in app.resources

xmlns:app="clr-namespace:tabbed_browser">  <!--application resources--> <application.resources>      <resourcedictionary>         <app:stringtruncator x:key="stringtruncator" />         <app:stringtruncatorfav x:key="stringtruncatorfav" />                 <app:appinfo x:key="appinfo" />         <app:booleantovisibilityconverter x:key="booleantovisibilityconverter" /            </resourcedictionary>  </application.resources> 

then in usercontrol xml refer via code

<grid x:name="layoutroot" background="{staticresource phonechromebrush}">     <textblock textwrapping="nowrap" x:name="txtpagetitle"              text="{binding browserviewmodel.pagetitle, converter={staticresource stringtruncator}}"              fontsize="{staticresource phonefontsizesmall}"                 verticalalignment="top"/> 

the stringtruncator simple converter append ... if string exceed length.

namespace tabbed_browser { public class stringtruncator : ivalueconverter {     public object convert(object value, type targettype, object parameter, cultureinfo culture)     {         if (value == null)             return "";           string str = value.tostring();         int maxchars = 44;         return str.length <= maxchars ? str : str.substring(0, maxchars) + "...";     }      public object convertback(object value, type targettype, object parameter, cultureinfo culture)     {         throw new notimplementedexception();     } } 

}

but run project following. removing stringtruncator converter in code eliminate error need use converter. missing?

{system.windows.markup.xamlparseexception:  cannot find resource name/key stringtruncator [line: 15 position: 22]   @ system.windows.application.loadcomponent(object component, uri resourcelocator)   @ tabbed_browser.user_controls.ucaddressbar.initializecomponent()   @ tabbed_browser.user_controls.ucaddressbar..ctor()} 

you should use dynamicresource instead, way applied @ runtime. or can add resources usercontrol.resources itself. or can also, must add namespace usercontrol also:

  text="{binding browserviewmodel.pagetitle, converter={app:stringtruncator}}" 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -